﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using System.Globalization;

using CE.Mail;
using CE.Image;
using CE.Global;
using CE.Database;
using CE.User;
using CE.PostCode;
using CE.CarInsurance;
using CE.Provider;
using CE.Security;
using CE.InputOut;
using CE.Payment;
using CXDecryption;

public partial class car_insurance_proposalforms_thaipaiboon_proposal_form : MyLanguageAndSessionBasePage
{
    public static Int64 _CarId, _CarMoreId, _UserId, _CXCTypeId, _ProviderId, _AgentId;
    public static DateTime _dtDOB1 = General.GetUTCDateTime();
    public static DateTime _dtDOB2 = General.GetUTCDateTime();
    string _redirectUrl = "";
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        //UICulture = selectedCulture;
        Culture = selectedCulture;
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Master.Page.Title = Resources.Title.ProposalTitle;

        #region "Session"

        if (Session[General.CarId] == null || Session[General.CarPolicyId] == null)
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/car-details", Page);
            Response.Redirect(_redirectUrl);
        }
        else
        {
            if (!CheckConfirmStatus())
            {
                //_redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes", Page);
                _redirectUrl = CE.Global.General.GetUrl("/car-insurance/car-details", Page);
                Response.Redirect(_redirectUrl);
            }
        }
        if (Session[CE.Global.General.CarResultId] != null)
        {
            if (Session[General.ProviderCompanyId].ToString() != "66")
            {
                if (Session[CE.Global.General.UserId] != null)
                {
                    //_redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes", Page);
                    _redirectUrl = CE.Global.General.GetUrl("/car-insurance/car-details", Page);
                    Response.Redirect(_redirectUrl);
                }
                else
                {
                    _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/car-details", Page);
                    Response.Redirect(_redirectUrl);
                }
            }
        }
        else
        {
            if (Session[CE.Global.General.UserId] != null)
            {
                //_redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes", Page);
                _redirectUrl = CE.Global.General.GetUrl("/car-insurance/car-details", Page);
                Response.Redirect(_redirectUrl);
            }
            else
            {
                _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/car-details", Page);
                Response.Redirect(_redirectUrl);
            }
        }
        #endregion

        if (!IsPostBack)
        {
            Session["CIMSG"] = null;
            Session["UMMSG"] = null;
            
            #region Set Property
            if (Session[CE.Global.General.UserPhoneNo] != null)
            {
                txtContactNo.PhoneNo = Session[CE.Global.General.UserPhoneNo].ToString();
            }
            if (Session[CE.Global.General.UserName] != null)
            {
                txtName.Text = Session[CE.Global.General.UserName].ToString();
            }
            lblDriverId1.Text = "0";
            lblDriverId2.Text = "0";
            LoadCarPolicyDetails();
            LoadCardExpiryMonth();
            LoadCardExpiryYear();
            #endregion

            #region Validation Effect

            txtName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtName.ClientID + "','" + rfvName.ClientID + "','" + revName.ClientID + "')");
            txtIdentificationNo.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtIdentificationNo.ClientID + "','" + rfvIdentificationNo.ClientID + "','" + revIdentificationNo.ClientID + "')");
            txtDriverName1.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverName1.ClientID + "','" + rfvDriverName1.ClientID + "')");
            txtDriverName2.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverName2.ClientID + "','" + rfvDriverName2.ClientID + "')");

            txtBeneficiaryName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtBeneficiaryName.ClientID + "','" + rfvBeneficiaryName.ClientID + "','" + revBeneficiaryName.ClientID + "')");
            txtCarPlate.Attributes.Add("onblur", "ShowValidationEffect('" + txtCarPlate.ClientID + "','" + rfvCarPlate.ClientID + "')");
            ddlCarPlateProvince.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCarPlateProvince.ClientID + "','" + rfvCarPlateProvince.ClientID + "')");
            txtPresentAddress.Attributes.Add("onblur", "ShowValidationEffect('" + txtPresentAddress.ClientID + "','" + rfvPresentAddress.ClientID + "')");
            ddlSubDistrict.Attributes.Add("onblur", "ShowValidationEffect('" + ddlSubDistrict.ClientID + "','" + rfvSubDistrict.ClientID + "')");
            ddlDistrict.Attributes.Add("onblur", "ShowValidationEffect('" + ddlDistrict.ClientID + "','" + rfvDistrict.ClientID + "')");
            ddlProvince.Attributes.Add("onblur", "ShowValidationEffect('" + ddlProvince.ClientID + "','" + rfvProvince.ClientID + "')");
            txtPostalCode.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtPostalCode.ClientID + "','" + rfvPostalCode.ClientID + "','" + revPostalCode.ClientID + "')");

            txtMailingAddress.Attributes.Add("onblur", "ShowValidationEffect('" + txtMailingAddress.ClientID + "','" + rfvMailingAddress.ClientID + "')");
            ddlMailingSubDistrict.Attributes.Add("onblur", "ShowValidationEffect('" + hidMailingSubDistrict.ClientID + "','" + rfvMailingSubDistrict.ClientID + "')");
            ddlMailingDistrict.Attributes.Add("onblur", "ShowValidationEffect('" + ddlMailingDistrict.ClientID + "','" + rfvMailingDistrict.ClientID + "')");
            ddlMailingProvince.Attributes.Add("onblur", "ShowValidationEffect('" + ddlMailingProvince.ClientID + "','" + rfvMailingProvince.ClientID + "')");
            txtMailingPostalCode.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtMailingPostalCode.ClientID + "','" + rfvMailingPostalCode.ClientID + "','" + revMailingPostalCode.ClientID + "')");

            rdoBankIn.Attributes.Add("onblur", "CheckPaymentTypeValidationCss();");
            rdoCreditCard.Attributes.Add("onblur", "CheckPaymentTypeValidationCss();");
            rdoSevenEleven.Attributes.Add("onblur", "CheckPaymentTypeValidationCss();");
            rdoTesco.Attributes.Add("onblur", "CheckPaymentTypeValidationCss();");
            rdoTrueMoney.Attributes.Add("onblur", "CheckPaymentTypeValidationCss();");
            #endregion

            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();

            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/results", Page);
            lblRedirect.Text = "http://" + _redirectUrl.Replace("~", HttpContext.Current.Request.Url.Host);
            //hplTopBack.NavigateUrl = _redirectUrl;
            //hplBottomBack.NavigateUrl = _redirectUrl;
            if (Session[CE.Global.General.AgentId] != null && Session[CE.Global.General.AgentBuyOnly] != null)
            {
                if (Session[CE.Global.General.AgentBuyOnly].ToString() == "1")
                {
                    btnBackTop.Visible = false;
                    btnBackHead.Visible = false;
                }
                else
                {
                    btnBackTop.Visible = true;
                    btnBackHead.Visible = true;
                }
            }
            else
            {
                btnBackTop.Visible = true;
                btnBackHead.Visible = true;
            }
            BindDdlCarPlateProvince();
            BindProvince();
            BindDdlMailingProvince();
            ddlDistrict.Items.Clear();
            ddlDistrict.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
            ddlMailingDistrict.Items.Clear();
            ddlMailingDistrict.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
            LoadDOB();
            Page.Form.DefaultButton = btnSubmit.UniqueID;
        }
        if (rdoBankIn.Checked || rdoCreditCard.Checked ||
            rdoSevenEleven.Checked || rdoTesco.Checked || rdoTrueMoney.Checked) txtPaymentType.Text = "1";
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.CarResultId] != null)
        {
            if (!CheckConfirmStatus())
            {
                //_redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes", Page);
                _redirectUrl = CE.Global.General.GetUrl("/car-insurance/car-details", Page);
                Response.Redirect(_redirectUrl);
            }
            if (Session[General.ProviderCompanyId].ToString() != "66")
            {
                if (Session[CE.Global.General.UserId] != null)
                {
                    //_redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes", Page);
                    _redirectUrl = CE.Global.General.GetUrl("/car-insurance/car-details", Page);
                    Response.Redirect(_redirectUrl);
                }
                else
                {
                    _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/car-details", Page);
                    Response.Redirect(_redirectUrl);
                }
            }
        }
        else
        {
            if (Session[CE.Global.General.UserId] != null)
            {
                //_redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes", Page);
                _redirectUrl = CE.Global.General.GetUrl("/car-insurance/car-details", Page);
                Response.Redirect(_redirectUrl);
            }
            else
            {
                _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/car-details", Page);
                Response.Redirect(_redirectUrl);
            }
        }


        if (txtName.Text == string.Empty)
        {
            lblMessage.Text = Resources.ProposalForm.UnfortunateUnable;//"Unfortunately, you are unable to proceed to complete this online proposal form.";
        }
        else
        {
            CheckMailingAddress();
            CheckValidation();
            ChangeValidationEffectServerSide("proposal");
            if (IsValid)
            {
                #region Driver DOB Validation
                if (rdoYesAddDriver.Checked)
                {
                    txtDriverCount.Text = ddlDriverCount.Text;
                    int _day1 = Convert.ToInt32(ddlDayDOB1.Text);
                    int _month1 = Convert.ToInt32(ddlMonthDOB1.Text);
                    int _year1 = Convert.ToInt32(ddlYearDOB1.Text);
                    if (!ValidDate(_year1, _month1, _day1))
                    {
                        lblMessage.ForeColor = System.Drawing.Color.Red;
                        lblMessage.Text = Resources.UserMessage.SelectValidDOB;
                        ddlDayDOB1.ControlStyle.CssClass = "proposal-combo validationError";
                        ddlMonthDOB1.ControlStyle.CssClass = "proposal-combo validationError";
                        ddlYearDOB1.ControlStyle.CssClass = "proposal-combo validationError";
                        return;
                    }
                    _dtDOB1 = new DateTime(_year1, _month1, _day1);
                    if (ddlDriverCount.Text == "2")
                    {
                        int _day2 = Convert.ToInt32(ddlDayDOB2.Text);
                        int _month2 = Convert.ToInt32(ddlMonthDOB2.Text);
                        int _year2 = Convert.ToInt32(ddlYearDOB2.Text);
                        if (!ValidDate(_year2, _month2, _day2))
                        {
                            lblMessage.ForeColor = System.Drawing.Color.Red;
                            lblMessage.Text = Resources.UserMessage.SelectValidDOB;
                            ddlDayDOB2.ControlStyle.CssClass = "proposal-combo validationError";
                            ddlMonthDOB2.ControlStyle.CssClass = "proposal-combo validationError";
                            ddlYearDOB2.ControlStyle.CssClass = "proposal-combo validationError";
                            return;
                        }
                        _dtDOB2 = new DateTime(_year2, _month2, _day2);
                    }
                }
                #endregion

                Int64 _carmoreresult = 0;
                Int64 driverresult = 0;
                ThaipaiboonCarMoreDetail _Thaipaibooncarmoredetail = new ThaipaiboonCarMoreDetail();
                ThaipaiboonCarMoreDetailDB _Thaipaibooncarmoredetaildb = new ThaipaiboonCarMoreDetailDB();

                if (Session[General.CarMoreDetailId] != null)
                {
                    _Thaipaibooncarmoredetail.CECarMoreDetailId = Convert.ToInt64(Session[General.CarMoreDetailId].ToString());
                }
                else
                {
                    _Thaipaibooncarmoredetail.CECarMoreDetailId = 0;
                }
                _Thaipaibooncarmoredetail.CECarId = Convert.ToInt64(Session[General.CarId].ToString());
                _Thaipaibooncarmoredetail.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());

                float _VarPremium = Convert.ToSingle(txtPremium.Text);
                float _VarCtpl = Convert.ToSingle(txtCTPL.Text);
                //Sakthi on 10 Nov 2014 - Start
                _Thaipaibooncarmoredetail.AnnualPremium = _VarPremium;
                //if (chkBuyCTPL.Checked)
                //{
                //    _Thaipaibooncarmoredetail.AnnualPremium = _VarPremium + _VarCtpl;
                //}
                //else
                //{
                //    _Thaipaibooncarmoredetail.AnnualPremium = _VarPremium;
                //}
                //Sakthi on 10 Nov 2014 - End
                _Thaipaibooncarmoredetail.TermPremium = (_Thaipaibooncarmoredetail.AnnualPremium / 4);

                //_Thaipaibooncarmoredetail.AnnualPremium = Convert.ToSingle(txtPremium.Text);
                _Thaipaibooncarmoredetail.Name = txtName.Text.Trim();
                _Thaipaibooncarmoredetail.IdentificationNo = txtIdentificationNo.Text.Trim();
                _Thaipaibooncarmoredetail.Occupation = ddlOccupation.GetOccupation();
                _Thaipaibooncarmoredetail.ContactNo = txtContactNo.GetPhoneNo();
                _Thaipaibooncarmoredetail.OfficePhoneNo = txtHomeOfficeNo.Text; //txtOfficePhoneNo.GetPhoneNo();
                //_Thaipaibooncarmoredetail.LicenseNo = txtLicenseNo.Text;
                _Thaipaibooncarmoredetail.BeneficiaryName = txtBeneficiaryName.Text;

                _Thaipaibooncarmoredetail.CarPlate = txtCarPlate.Text;
                _Thaipaibooncarmoredetail.CarPlateProvince = ddlCarPlateProvince.SelectedItem.Text;
                _Thaipaibooncarmoredetail.PresentAddress = txtPresentAddress.Text;
                _Thaipaibooncarmoredetail.SubDistrict = hidSubDistrictName.Value;
                _Thaipaibooncarmoredetail.District = hidDistrictName.Value;
                _Thaipaibooncarmoredetail.Province = ddlProvince.SelectedItem.Text;
                _Thaipaibooncarmoredetail.PostalCode = txtPostalCode.Text;
                _Thaipaibooncarmoredetail.IsMailingAddressDiff = rdoMailingAddressNo.Checked;
                _Thaipaibooncarmoredetail.MailingAddress = txtMailingAddress.Text;
                _Thaipaibooncarmoredetail.MailingSubDistrict = hidMailingSubDistrictName.Value;
                _Thaipaibooncarmoredetail.MailingDistrict = hidMailingDistrictName.Value;
                _Thaipaibooncarmoredetail.MailingProvince = ddlMailingProvince.SelectedValue == "-1" ? "" : ddlMailingProvince.SelectedItem.Text;
                _Thaipaibooncarmoredetail.MailingPostalCode = txtMailingPostalCode.Text;

                _Thaipaibooncarmoredetail.Info1 = ddlProvince.SelectedValue + ',' + hidDistrict.Value + ',' + hidSubDistrict.Value;
                _Thaipaibooncarmoredetail.Info2 = ddlMailingProvince.SelectedValue + ',' + hidMailingDistrict.Value + ',' + hidMailingSubDistrict.Value;

                _Thaipaibooncarmoredetail.EngineNumber = txtEngineNumber.Text;
                _Thaipaibooncarmoredetail.ChassisNumber = txtChassisNumber.Text;
                //_Thaipaibooncarmoredetail.IsRegisteredOwner = rdoROwnerYes.Checked;
                _Thaipaibooncarmoredetail.IsCTPL = chkBuyCTPL.Checked;
                _Thaipaibooncarmoredetail.CTPL = Convert.ToSingle(txtCTPL.Text);
                if (rdoBankIn.Checked == true)
                {
                    _Thaipaibooncarmoredetail.PaymentType = "Bank In";
                    switch (rdoBankInOption.SelectedItem.Value)
                    {
                        case "BKK":
                            _Thaipaibooncarmoredetail.PaymentBank = "BKK";
                            break;
                        case "KBANK":
                            _Thaipaibooncarmoredetail.PaymentBank = "KBANK";
                            break;
                        case "KTB":
                            _Thaipaibooncarmoredetail.PaymentBank = "KTB";
                            break;
                        case "SCB":
                            _Thaipaibooncarmoredetail.PaymentBank = "SCB";
                            break;
                    }
                }
                else if (rdoCreditCard.Checked == true)
                {
                    _Thaipaibooncarmoredetail.PaymentType = "CreditCard";
                }
                else if (rdoSevenEleven.Checked == true)
                {
                    _Thaipaibooncarmoredetail.PaymentType = "Seven";
                }
                else if (rdoTesco.Checked == true)
                {
                    _Thaipaibooncarmoredetail.PaymentType = "Tesco";
                }
                else if (rdoTrueMoney.Checked == true)
                {
                    _Thaipaibooncarmoredetail.PaymentType = "TrueMoney";
                }

                _Thaipaibooncarmoredetail.OrderRefNoId = GetOrderRefNoId();
                _Thaipaibooncarmoredetail.OrderRefNo = GetOrderRefNo();
                _Thaipaibooncarmoredetail.PaymentStatus = false;

                _Thaipaibooncarmoredetail.QuoteRefNo = lblQRefNo.Text.Trim();

                if (Session[CE.Global.General.UserId] != null)
                {
                    _Thaipaibooncarmoredetail.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _Thaipaibooncarmoredetail.RefCEUserId = 0;
                }

                _Thaipaibooncarmoredetail.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                _Thaipaibooncarmoredetail.Status = true;
                _Thaipaibooncarmoredetail.CarResultId = Convert.ToInt64(Session[General.CarResultId].ToString());
                if (Session[CE.Global.General.AgentId] != null)
                {
                    _Thaipaibooncarmoredetail.Ninfo4 = Convert.ToInt64(Session[CE.Global.General.AgentId].ToString());
                    if (rdoBankIn.Checked == true)
                    {
                        _Thaipaibooncarmoredetail.Ninfo5 = 102;
                    }
                    else if (rdoCreditCard.Checked == true)
                    {
                        _Thaipaibooncarmoredetail.Ninfo5 = 202;
                    }
                    else if (rdoSevenEleven.Checked == true)
                    {
                        _Thaipaibooncarmoredetail.Ninfo5 = 302;
                    }
                    else if (rdoTesco.Checked == true)
                    {
                        _Thaipaibooncarmoredetail.Ninfo5 = 402;
                    }
                    else if (rdoTrueMoney.Checked == true)
                    {
                        _Thaipaibooncarmoredetail.Ninfo5 = 502;
                    }
                }
                else
                {
                    _Thaipaibooncarmoredetail.Ninfo4 = 0;
                    _Thaipaibooncarmoredetail.Ninfo5 = 0;
                }

                _carmoreresult = _Thaipaibooncarmoredetaildb.Insert(_Thaipaibooncarmoredetail);

                if (_carmoreresult > 0)
                {
                    //[Yui] @13/09/2013
                    if (lblSelectInsurer.Text.Trim() == "GluayGluay.com Special")
                        SaveConfirmDisclaimer(int.Parse(Session[General.ProviderCompanyId].ToString()), _carmoreresult);
                    //--- End ---

                    Session[CE.Global.General.CarMoreDetailId] = _carmoreresult.ToString();
                    Int64 _paymentresult = 0;
                    _paymentresult = 1;
                    if (_paymentresult > 0)
                    {
                        if (txtDriverCount.Text.Trim() != "0")
                        {
                            if (!UpdateDriverDetails())
                            {
                                lblMessage.Text = Resources.ProposalForm.CarDriverSaveFaild;//"Car Drivers failed to save!";
                            }
                            else
                            {
                                driverresult = 1;
                            }
                        }
                        else
                        {
                            driverresult = 1;
                        }

                        if (driverresult > 0)
                        {
                            Session[CE.Global.General.CarMoreDetailId] = _carmoreresult.ToString();
                            UserConfirmation _userconfirm = new UserConfirmation();
                            UserConfirmationDB _userconfirmdb = new UserConfirmationDB();
                            _userconfirm.ConfirmationType = "CI";
                            _userconfirm.CurrentStep = 4;
                            _userconfirm.UserSelectedId = Convert.ToInt64(Session[General.CarResultId].ToString());
                            _userconfirm.FirstStepId = Convert.ToInt64(Session[General.CarId].ToString());
                            if (Session[General.UserId] != null)
                            {
                                _userconfirm.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                            }
                            else
                            {
                                _userconfirm.RefCEUserId = 0;
                            }
                            _userconfirm.IsConfirm = true;
                            _userconfirm.ResultStatus = "Complete";
                            _userconfirm.IsComplete = true;
                            Int64 _result = _userconfirmdb.Insert(_userconfirm);
                            if (_result > 0)
                            {
                                string _provideid = Encode(Session[General.ProviderCompanyId].ToString());
                                string _refid = "";
                                string convertno = General.GetRefNumber(Convert.ToInt64(Session[CE.Global.General.CarId]));
                                _refid = "A" + convertno;

                                if (Session[General.CarResultId] != null)
                                {
                                    SendProposalToAgent(Session[General.CarResultId].ToString());
                                }
                                if (rdoBankIn.Checked)
                                {
                                    ProposalNotification();
                                    General.ClearAllSession(this.Page, "ALL");
                                    _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/user-message", Page);
                                    Session["CIMSG"] = _provideid + "," + _refid + "," + "OTHER";
                                    Response.Redirect(_redirectUrl);
                                }
                                else if (rdoCreditCard.Checked)
                                {
                                    float _fAmount = _Thaipaibooncarmoredetail.AnnualPremium;
                                    //float _fAmount = Convert.ToSingle(txtPremium.Text);
                                    string _strAmount, eAmount, _strOrderRefNo, eOrderRefNo;
                                    _strAmount = ""; eAmount = ""; _strOrderRefNo = ""; eOrderRefNo = "";
                                    string key = "cxDAtravel";
                                    CXDecryption.Decryption cxd = new CXDecryption.Decryption();
                                    _strAmount = _fAmount.ToString();
                                    _strOrderRefNo = _Thaipaibooncarmoredetail.OrderRefNo;
                                    if (_strAmount.ToString() != "" && _strAmount.ToString() != null)
                                    {
                                        byte[] Amount = cxd.Encrypt(_strAmount, key);
                                        eAmount = Convert.ToBase64String(Amount);
                                    }
                                    if (_strOrderRefNo.ToString() != "" && _strOrderRefNo.ToString() != null)
                                    {
                                        byte[] OrderRefNo = cxd.Encrypt(_strOrderRefNo, key);
                                        eOrderRefNo = Convert.ToBase64String(OrderRefNo);
                                    }
                                    string URL = ConfigurationManager.AppSettings["TH.BKKPaymentPage"].ToString();
                                    URL += "?pa=" + eAmount + "&orno=" + eOrderRefNo;
                                    Response.Redirect(URL);
                                }
                                else if (rdoSevenEleven.Checked || rdoTrueMoney.Checked || rdoTesco.Checked)
                                {
                                    SendCounterServiceNotification();

                                    string carID = _carmoreresult.ToString(); //Session[CE.Global.General.CarId].ToString();
                                    string userEmail = Session[General.UserEmail].ToString();
                                    General.ClearAllSession(this.Page, "ALL");
                                    Session["CTSV123"] = postBackToMerchant(carID, userEmail);
                                    _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/counterservice/counterservice.aspx", Page);
                                    Session["CTSVMSG"] = Session[General.ProviderCompanyId].ToString() + "," + _refid;
                                    Response.Redirect(_redirectUrl);
                                }
                            }
                            else
                            {
                                lblMessage.Text = Resources.ProposalForm.ConfirmStatusFaild;//"Can't update confirmation status.";
                            }
                        }
                    }
                }
            }
        }
    }

    private string postBackToMerchant(string carID, string userEmail)
    {
        int expDate = 0;
        DateTime dteToday = new DateTime(General.GetUTCDateTime().Year, General.GetUTCDateTime().Month, General.GetUTCDateTime().Day, 23, 0, 0);

        if (lblCommencementdate.Text.Trim() != "")
        {
            string[] splitDate = lblCommencementdate.Text.Split('-');
            if (splitDate.Length == 3)
            {
                int yer = 0;
                string[] mth;
                if (Session["Language"].ToString() == "en-US")
                {
                    mth = new string[12] { "jan", "feb", "mar", "apr",
                               "may", "jun", "jul", "aug",
                               "sep", "oct", "nov", "dec"};
                    yer = int.Parse(splitDate[2]);
                }
                else
                {
                    mth = new string[12] { "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.",
                               "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.",
                               "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค."};
                    yer = int.Parse(splitDate[2]) - 543;
                }

                int cMth = 0;
                for (int m = 0; m < 12; m++)
                {
                    if (splitDate[1].ToLower() == mth[m])
                    {
                        cMth = m + 1;
                        break;
                    }
                }

                DateTime dteExp = new DateTime(yer, cMth, int.Parse(splitDate[0]), 23, 0, 0);
                double dateDiff = (dteExp.Date - dteToday).TotalDays;

                if (dateDiff >= 7)
                {
                    expDate = 7;
                }
                else
                {
                    expDate = Convert.ToInt32(dateDiff);
                    if (expDate < 0) expDate = 0;
                }
            }
        }

        //MerchantID+InvoiceNo+Amount
        //InvoiceNo = Convert.ToInt64(Session[General.CarId].ToString())
        string totalprice = "";
        if (!chkBuyCTPL.Checked)
        {
            totalprice = lblTotalPremium.Text.Replace(Resources.CarInsurance.Baht, "").Trim().Replace(",", "").Replace(".", "").PadLeft(12, '0');
        }
        else
        {
            totalprice = lblTotalPremiumPlusCtpl.Text.Replace(Resources.CarInsurance.Baht, "").Trim().Replace(",", "").Replace(".", "").PadLeft(12, '0');
        }
        string hashVal = "256" + carID + totalprice;
        hash_hmac_sha1 hash = new hash_hmac_sha1();

        StringBuilder sendXml = new StringBuilder();
        sendXml.Append("<OneTwoThreeReq>");
        sendXml.Append("<Version>1.1</Version>");
        sendXml.Append("<TimeStamp>" + General.GetUTCDateTime().ToString("yyyy-MM-dd HH:mm:ss:fff", new System.Globalization.CultureInfo("en-US")) + "</TimeStamp>"); //2014-01-09 11:50:12:888
        sendXml.Append("<MessageID>" + lblQRefNo.Text + "</MessageID>");
        sendXml.Append("<MerchantID>256</MerchantID>");
        sendXml.Append("<InvoiceNo>" + carID + "</InvoiceNo>");
        sendXml.Append("<Amount>" + totalprice + "</Amount>");
        sendXml.Append("<Discount>000000000000</Discount>");
        sendXml.Append("<ServiceFee>000000000000</ServiceFee>");
        sendXml.Append("<ShippingFee>000000000000</ShippingFee>");
        sendXml.Append("<CurrencyCode>THB</CurrencyCode>");
        sendXml.Append("<CountryCode>THA</CountryCode>");
        sendXml.Append("<ProductDesc>" + lblSelectInsurer.Text + "</ProductDesc>");
        sendXml.Append("<PaymentItems>");
        sendXml.Append("<PaymentItem id=\"1\" name=\"" + lblPackageName.Text + "\" price=\"" + totalprice + "\" quantity=\"1\" />");
        sendXml.Append("</PaymentItems>");
        sendXml.Append("<PayerName>" + txtName.Text + "</PayerName>");
        sendXml.Append("<PayerEmail>" + userEmail + "</PayerEmail>");
        sendXml.Append("<PayerMobile>" + txtContactNo.GetPhoneNo() + "</PayerMobile>");
        sendXml.Append("<ShippingAddress>Bangkok</ShippingAddress>");
        sendXml.Append("<MerchantUrl>" + ConfigurationManager.AppSettings["Service123Return"].ToString() + "</MerchantUrl>"); //the payer clicked on GoBackMerchant button at 1-2-3 result page
        sendXml.Append("<APICallUrl></APICallUrl>"); //after payment is PAID or PENDING
        if (rdoSevenEleven.Checked)
        {
            sendXml.Append("<AgentCode>7ELEVEN</AgentCode>");
        }
        else if (rdoTesco.Checked)
        {
            sendXml.Append("<AgentCode>TESCO</AgentCode>");
        }
        else if (rdoTrueMoney.Checked)
        {
            sendXml.Append("<AgentCode>TRUEMONEY</AgentCode>");
        }
        //7ELEVEN= 7 Eleven Counter Service
        //TRUEMONEY= True Money Shop
        //TESCO= Tesco Lotus Counter Service
        sendXml.Append("<ChannelCode>OVERTHECOUNTER</ChannelCode>");
        if (Session["Language"].ToString() == "en-US")
        {
            sendXml.Append("<PayInSlipInfo>If you need any helps, please call our contact#|Tel.: 02-268-8222 or Email: support@gluaygluay.com|GG Ref.#: " + lblQRefNo.Text + "</PayInSlipInfo>"); //If your purchase amount is less than 2000 Baht, you have to pay 59 Baht as convenience fee.| Our hot promotions are iPhone5, Galaxy S3. | 
        }
        else
        {
            sendXml.Append("<PayInSlipInfo>หากต้องการความช่วยเหลือโปรดติดต่อหาเราที่|เบอร์: 02-268-8222 หรืออีเมล์: support@gluaygluay.com|หมายเลขอ้างอิง: " + lblQRefNo.Text + "</PayInSlipInfo>");
        }
        sendXml.Append("<PaymentExpiry>" + dteToday.AddDays(expDate).ToString("yyyy-MM-dd HH:mm:ss", new System.Globalization.CultureInfo("en-US")) + "</PaymentExpiry>");
        sendXml.Append("<UserDefined1></UserDefined1>");
        sendXml.Append("<UserDefined2></UserDefined2>");
        sendXml.Append("<UserDefined3></UserDefined3>");
        sendXml.Append("<UserDefined4></UserDefined4>");
        sendXml.Append("<UserDefined5></UserDefined5>");
        sendXml.Append("<HashValue>" + hash.getHMAC(hashVal, "5G7JL5J3RTZ0V2BW32R3TQ3953Q040R5") + "</HashValue>");
        sendXml.Append("</OneTwoThreeReq>");

        SinaptIQPKCS7.PKCS7 pkcs7 = new SinaptIQPKCS7.PKCS7();

        string base64Str = pkcs7.encryptMessage(sendXml.ToString(), pkcs7.getPublicCert(Request.PhysicalApplicationPath + @"\App_Code\counterservice\123Public.cer"));

        StringBuilder sb = new StringBuilder();
        sb.Append("<html><head><title>To 123</title></head>");
        sb.Append("<body>");
        sb.Append("<form name=\"PostForm\" id=\"PostForm\" action=\"https://secure.123.co.th/Payment/paywith123.aspx\" method=\"post\">");
        sb.Append("<input type=\"hidden\" name=\"OneTwoThreeReq\" value=\"" + base64Str + "\" />");
        sb.Append("<input type=\"submit\" value=\"\" name=\"submit\" style=\"width:0px\" />");
        sb.Append("<script language=\"JavaScript\" type=\"text/javascript\">");
        sb.Append("window.onload = function()");
        sb.Append("{");
        sb.Append("document.PostForm.submit.click();");
        sb.Append("}");
        sb.Append("</script>");
        sb.Append("</form></body></html>");

        return sb.ToString();
    }

    private bool SendCounterServiceNotification()
    {
        Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());
        CE.User.Profile usrprofile = new Profile();
        ProfileDB usrprofiledb = new ProfileDB();

        usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

        string userfirstname = "";

        if (usrprofile != null)
        {
            userfirstname = usrprofile.FirstName;
        }

        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        string _Premium = "";
        string _Gender = "";
        string _DOB = "";
        string _Occupation = "";
        string _InsuranceType = "";
        string _NCB = "";

        string _GarageType = "";
        string _CarYear = "";
        string _CarMakeModel = "";
        string _CarType = "";
        string _CarPlate = "";
        string _NameDriver = "";
        string _Name = "";
        string _PolicyStartDate = "";
        string _isCTPL = "No";
        string _CTPL = "";

        Int64 _companyId = 0;

        System.Data.DataTable _dtSeletectItem = new System.Data.DataTable("SelectedResultItem");
        _dtSeletectItem = _db.GetDataTable("Select * from tblCarInsuranceSelectItemTH WHERE CarId = " + _carId.ToString());
        if (_dtSeletectItem != null && _dtSeletectItem.Rows.Count > 0)
        {
            _companyId = Convert.ToInt64(_dtSeletectItem.Rows[0]["ProviderCompanyId"].ToString());
            _Premium = Convert.ToSingle(_dtSeletectItem.Rows[0]["AnnualPremium"].ToString()).ToString("#.00");
        }
        CarInsuranceCompletedItemDB _carinsurancecompleteditemdb = new CarInsuranceCompletedItemDB();
        _dsInsurance = _carinsurancecompleteditemdb.GetCarInsuranceCompletedItem(_carId, _companyId);
        if (_dsInsurance != null && _dsInsurance.Tables[0].Rows.Count > 0)
        {
            _Gender = _dsInsurance.Tables[0].Rows[0]["Gender"].ToString() == "Male" ? Resources.CarInsurance.Male : Resources.CarInsurance.Female;
            _DOB = Convert.ToDateTime(_dsInsurance.Tables[0].Rows[0]["DOB"]).ToString("dd-MMM-yyyy");
            if (CE.Global.General.SetCulture() == "th-TH")
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["THOccupation"].ToString();
            }
            else
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["ENOccupation"].ToString();
            }
            switch (_dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString())
            {
                case "Class 1":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOne;
                    _NCB = _dsInsurance.Tables[0].Rows[0]["NCB"].ToString();
                    break;
                case "Class 1 (Low Cost)":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOneLowCost;
                    _NCB = "N/A";
                    break;
                case "Class 2+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    _NCB = "N/A";
                    break;
                case "Class 3+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThreePlus;
                    _NCB = "N/A";
                    break;
                case "Class 3":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThree;
                    _NCB = "N/A";
                    break;
            }

            _GarageType = _dsInsurance.Tables[0].Rows[0]["GarageType"].ToString() == "Authorized" ? Resources.CarInsurance.Garage_Authorized : Resources.CarInsurance.Garage_Dealer;
            _CarYear = _dsInsurance.Tables[0].Rows[0]["CarModelYear"].ToString();
            _CarMakeModel = _dsInsurance.Tables[0].Rows[0]["MakeModelDesc"].ToString();
            _CarType = _dsInsurance.Tables[0].Rows[0]["VehicleType"].ToString() == "Private Use" ? Resources.CarInsurance.VehicleType_Private : Resources.CarInsurance.VehicleType_Commercial;
            _NameDriver = _dsInsurance.Tables[0].Rows[0]["Driver"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesSpecify : Resources.CarInsurance.Option_NoSpecify;

            if (_dsInsurance.Tables[1].Rows.Count > 0)
            {
                _CarPlate = _dsInsurance.Tables[1].Rows[0]["VehicleNo"].ToString();
                if (_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"] != DBNull.Value)
                {
                    _PolicyStartDate = Convert.ToDateTime(_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"]).ToString("dd-MMM-yyyy");
                }
                _Name = _dsInsurance.Tables[1].Rows[0]["Name"].ToString();
                _refNo = _dsInsurance.Tables[1].Rows[0]["QuoteRefNo"].ToString();

                _isCTPL = _dsInsurance.Tables[1].Rows[0]["CTPL"].ToString();
                _CTPL = _dsInsurance.Tables[1].Rows[0]["CTPLAmount"].ToString();
            }
        }

        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");
        string _isOnline = "Online";
        if (_strCXLive == "0")
            _isOnline = "Test";

        string _emailTo = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_TO"].ToString();
        string _emailCC = "";
        string _emailBCC = "";
        string _customername = Session[General.UserName].ToString();
        string _emailSubject = "";
        if (rdoSevenEleven.Checked)
        {
            _emailSubject = "<" + _isOnline + "> - " + Resources.Proposal.PendingPayment + " 7/11 - " + Resources.EmailMessage.AZCPSubject;
        }
        else if (rdoTesco.Checked)
        {
            _emailSubject = "<" + _isOnline + "> - " + Resources.Proposal.PendingPayment + " Tesco - " + Resources.EmailMessage.AZCPSubject;
        }
        else if (rdoTrueMoney.Checked)
        {
            _emailSubject = "<" + _isOnline + "> - " + Resources.Proposal.PendingPayment + " True Money - " + Resources.EmailMessage.AZCPSubject;
        }

        string _mailBody = "";

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center> <br /><br />";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
        _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
        _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.PendingPayment + "</strong><br /><br />";
        _mailBody += Resources.Proposal.AgentMessage + "<br/><br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.OrderNo + " </strong>" + _refNo + "</td><td width='50%' align='right' valign='top'></td></tr>";
        _mailBody += "</table>";

        _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        _mailBody += "<tr><td width='50%' valign='top'>" + Resources.Proposal.InsuranceType + " " + _InsuranceType + "</td><td width='50%;' valign='top'>Car Id.: " + Session[General.CarId].ToString() + "</td>";
        _mailBody += "</tr><tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + General.GetUTCDateTime().ToString("dd/MMM/yyyy") + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.GarageType + ": " + _GarageType + "</td><td valign='top'>" + Resources.Proposal.NamedDrivers + ": " + _NameDriver + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.PolicyStartDate + ": " + _PolicyStartDate + " </td><td valign='top'>" + Resources.Proposal.NCB + ": " + _NCB + "</td></tr>";
        _mailBody += "</table> <br /><br />";
        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'>";
        _mailBody += "</td></tr></table>";
        _mailBody += "</center></body>";

        if (MyMailManager.SendSelectedCARMessageToAgent(_emailTo, _emailCC, _emailBCC, _emailSubject + " (Ref No : " + _refNo + ") ", _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    public void LoadCarPolicyDetails()
    {
        if (Session[CE.Global.General.UserId] != null)
        {
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        }
        else
        {
            _UserId = 0;
        }
        _CarId = Convert.ToInt64(Session[General.CarId].ToString());
        _CXCTypeId = Convert.ToInt64(Session[CE.Global.General.CarResultId].ToString());
        _ProviderId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());

        DataSet _dtProvider = new DataSet();
        ThaipaiboonCarMoreDetail _Thaipaibooncarmoredetail = new ThaipaiboonCarMoreDetail();
        ThaipaiboonCarMoreDetailDB _Thaipaibooncarmoredetaildb = new ThaipaiboonCarMoreDetailDB();
        _dtProvider = _Thaipaibooncarmoredetaildb.GetCarPolicyDetails(_CarId, _UserId, _CXCTypeId, _ProviderId);
        if (_dtProvider != null && _dtProvider.Tables.Count > 0)
        {
            if (_dtProvider.Tables[0].Rows.Count > 0 && _dtProvider.Tables[1].Rows.Count > 0 && _dtProvider.Tables[2].Rows.Count > 0)
            {
                lblYrofManufacture.Text = _dtProvider.Tables[0].Rows[0]["ManufactYear"].ToString();
                lblCarModelYear.Text = _dtProvider.Tables[0].Rows[0]["RegYear"].ToString();
                lblCarMakemodel.Text = _dtProvider.Tables[0].Rows[0]["MakeModelDesc"].ToString();
                lblRedPlate.Text = _dtProvider.Tables[0].Rows[0]["RedPlate"].ToString();
                lblCTPL.Text = _dtProvider.Tables[1].Rows[0]["CTPL"].ToString();
                lblCTPLAmount.Text = _dtProvider.Tables[1].Rows[0]["CTPL"].ToString() + " " + Resources.CarInsurance.Baht;
                txtCTPL.Text = _dtProvider.Tables[1].Rows[0]["CTPL"].ToString();
                //Sakthi on 10 Nov 2014 - Start
                chkBuyCTPL.Checked = false;
                if (_dtProvider.Tables[0].Rows[0]["CTPL"] != DBNull.Value && _dtProvider.Tables[0].Rows[0]["CTPL"].ToString() != string.Empty
                    && _dtProvider.Tables[0].Rows[0]["CTPL"].ToString().ToUpper() == "YES")
                {
                    chkBuyCTPL.Checked = true;
                }
                //Sakthi on 10 Nov 2014 - End
                lblNCB.Text = _dtProvider.Tables[0].Rows[0]["NCDPercent"].ToString() + "%";
                float _InsuredAmt = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["SumInsured"].ToString());
                if (_InsuredAmt > 0)
                {
                    lblSumInsured.Text = String.Format("{0:0,0}", _InsuredAmt) + " " + Resources.CarInsurance.Baht;  //String.Format("฿{0:0,0.00}", _InsuredAmt);
                }
                else
                {
                    lblSumInsured.Text = "N/A";
                }
                rdoNoAddDriver.Checked = true;
                txtDriverCount.Text = _dtProvider.Tables[0].Rows[0]["NoOfDriver"].ToString();
                if (_dtProvider.Tables[0].Rows[0]["NoOfDriver"].ToString() != "0")
                {
                    rdoYesAddDriver.Checked = true;
                    ddlDriverCount.Text = _dtProvider.Tables[0].Rows[0]["NoOfDriver"].ToString();
                }
                EnableDriverPanels();
                lblCommencementdate.Text = "";
                if (_dtProvider.Tables[0].Rows[0]["CommenceDate"].ToString() != "")
                {
                    lblCommencementdate.Text = Convert.ToDateTime(_dtProvider.Tables[0].Rows[0]["CommenceDate"]).ToString("dd-MMM-yyyy");
                }

                if (_dtProvider.Tables[1].Rows[0]["PlanName"].ToString() != "GluayGluay.com Special")
                {
                    lblSelectInsurer.Text = _dtProvider.Tables[1].Rows[0]["CompanyName"].ToString();
                    lblPackages.Text = _dtProvider.Tables[1].Rows[0]["PlanName"].ToString();

                    //[Yui] @13/09/2013
                    cust_Disclaimer.Enabled = false;
                }
                else
                {
                    lblInsurance.Text = Resources.ProposalForm.Package;
                    lblSelectInsurer.Text = _dtProvider.Tables[1].Rows[0]["PlanName"].ToString();
                    lblPackageName.Text = Resources.ProposalForm.PackageCondition;
                    lblPackages.Text = Resources.CarInsuranceResultPage.SpecialNCB;

                    //[Yui] @13/09/2013 
                    divDisclaimerTab.Style.Add("display", "");
                }
                //float _APremium = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString());//Hide for Sop Request on 12 Sep 2011 by Skype
                float _APremium = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString());//Change for Sop Request on 12 Sep 2011 by Skype
                lblPremiums.Text = String.Format("{0:0,0.00}", _APremium) + " " + Resources.CarInsurance.Baht;//String.Format("฿{0:0,0.00}", _APremium);
                //txtPremium.Text = _dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString();//Hide for Sop Request on 12 Sep 2011 by Skype
                txtPremium.Text = _dtProvider.Tables[1].Rows[0]["PromotionPrice"].ToString();//Hide for Sop Request on 12 Sep 2011 by Skype

                float _Promotion = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["PromotionPrice"].ToString());
                lblPromotion.Text = String.Format("{0:0,0.00}", _Promotion);// +" " + Resources.CarInsurance.Baht;

                //float _VarPremium = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString());//Hide for Sop Request on 12 Sep 2011 by Skype
                float _VarPremium = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["PromotionPrice"].ToString());//Change for Sop Request on 12 Sep 2011 by Skype
                float _VarCtpl = Convert.ToSingle(_dtProvider.Tables[1].Rows[0]["CTPL"].ToString());
                //Sakthi on 10 Nov 2014 - Start
                //float _VarTotalPremiumPlusCtpl = _VarPremium + _VarCtpl;
                float _VarTotalPremiumPlusCtpl = _VarPremium;
                //Sakthi on 10 Nov 2014 - End
                lblTotalPremiumPlusCtpl.Text = String.Format("{0:0,0.00}", _VarTotalPremiumPlusCtpl) + " " + Resources.CarInsurance.Baht;
                lblTotalPremium.Text = String.Format("{0:0,0.00}", _VarPremium) + " " + Resources.CarInsurance.Baht;
                float __VarMonthlyPremiumPlusCtpl = _VarTotalPremiumPlusCtpl / 4;
                float __VarMonthlyPremium = _VarPremium / 4;
                lblPremiumMonthlyPlusCtpl.Text = String.Format("{0:0,0.00}", __VarMonthlyPremiumPlusCtpl) + " " + Resources.CarInsurance.Baht + " (" + Resources.ProposalForm.PerMonth + ")";
                lblPremiumMonthly.Text = String.Format("{0:0,0.00}", __VarMonthlyPremium) + " " + Resources.CarInsurance.Baht + " (" + Resources.ProposalForm.PerMonth + ")";

                //Sakthi - for Sop Request on 12 Sep 2011 by Skype -- Start
                string IsIncludeCMI = _dtProvider.Tables[1].Rows[0]["IsIncludeCMI"].ToString();
                if (IsIncludeCMI == "True" || IsIncludeCMI == "1")
                {
                    txtIsIncludeCMI.Text = "1";
                }
                else
                {
                    txtIsIncludeCMI.Text = "0";
                }
                //Sakthi - for Sop Request on 12 Sep 2011 by Skype -- End

                #region Sakthi on 28 Nov 2014 - CMI Breakdown
                bool IncludeCMI = false;
                Int32 intClass = 10;
                string strClass = _dtProvider.Tables[1].Rows[0]["InsuranceType"].ToString();
                if (!bool.TryParse(IsIncludeCMI, out IncludeCMI))
                {
                    IncludeCMI = false;
                }
                if (!Int32.TryParse(strClass, out intClass))
                {
                    intClass = 10;
                }
                if (IncludeCMI)
                {
                    float _beforeCMI = 0.0f;
                    _beforeCMI = _Promotion - _VarCtpl;
                    lblBeforeCMITitle.Text = "";
                    lblCMIAmountTitle.Text = Resources.CarInsurance.CMI;
                    lblBeforeCMI.Text = String.Format("{0:0,0.00}", _beforeCMI);
                    lblCMIAmount.Text = String.Format("{0:0,0.00}", _VarCtpl);
                    trBeforeCMI.Visible = true;
                    trCMI.Visible = true;
                    if (intClass == 10)
                    {
                        lblBeforeCMITitle.Text = Resources.CarInsurance.Insurance_ClassOne;
                    }
                    else if (intClass == 21)
                    {
                        lblBeforeCMITitle.Text = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    }
                    else if (intClass == 21)
                    {
                        lblBeforeCMITitle.Text = Resources.CarInsurance.Insurance_ClassThreePlus;
                    }
                    else if (intClass == 30)
                    {
                        lblBeforeCMITitle.Text = Resources.CarInsurance.Insurance_ClassThree;
                    }
                    lblPremiumTitle.Text = Resources.CarInsurance.Total;
                }
                else
                {
                    lblBeforeCMITitle.Text = "";
                    lblCMIAmountTitle.Text = "";
                    lblBeforeCMI.Text = "";
                    lblCMIAmount.Text = "";
                    trBeforeCMI.Visible = false;
                    trCMI.Visible = false;
                    if (intClass == 10)
                    {
                        lblBeforeCMITitle.Text = Resources.CarInsurance.Insurance_ClassOne;
                        lblPremiumTitle.Text = Resources.CarInsurance.Insurance_ClassOne;
                    }
                    else if (intClass == 21)
                    {
                        lblBeforeCMITitle.Text = Resources.CarInsurance.Insurance_ClassTwoPlus;
                        lblPremiumTitle.Text = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    }
                    else if (intClass == 21)
                    {
                        lblBeforeCMITitle.Text = Resources.CarInsurance.Insurance_ClassThreePlus;
                        lblPremiumTitle.Text = Resources.CarInsurance.Insurance_ClassThreePlus;
                    }
                    else if (intClass == 30)
                    {
                        lblBeforeCMITitle.Text = Resources.CarInsurance.Insurance_ClassThree;
                        lblPremiumTitle.Text = Resources.CarInsurance.Insurance_ClassThree;
                    }
                }
                #endregion

                string convertno = General.GetRefNumber(_CarId);
                if (_dtProvider.Tables[1].Rows[0]["PlanName"].ToString() != "GluayGluay.com Special")
                {
                    if (_ProviderId == 11)
                    {
                        lblQRefNo.Text = "AZC" + convertno.ToString();
                    }
                    else if (_ProviderId == 12)
                    {
                        lblQRefNo.Text = "MSI" + convertno.ToString();
                    }
                    else if (_ProviderId == 16)
                    {
                        lblQRefNo.Text = "AXA" + convertno.ToString();
                    }
                    else if (_ProviderId == 29)
                    {
                        lblQRefNo.Text = "LMG" + convertno.ToString();
                    }
                    else if (_ProviderId == 31)
                    {
                        lblQRefNo.Text = "CTS" + convertno.ToString();
                    }
                    else if (_ProviderId == 32)
                    {
                        lblQRefNo.Text = "BKI" + convertno.ToString();
                    }
                    else if (_ProviderId == 33)
                    {
                        lblQRefNo.Text = "MTI" + convertno.ToString();
                    }
                    else if (_ProviderId == 35)
                    {
                        lblQRefNo.Text = "KPI" + convertno.ToString();
                    }
                    else if (_ProviderId == 39)
                    {
                        lblQRefNo.Text = "MIR" + convertno.ToString();
                    }
                    else if (_ProviderId == 41)
                    {
                        lblQRefNo.Text = "KSK" + convertno.ToString();
                    }
                    else if (_ProviderId == 43)
                    {
                        lblQRefNo.Text = "SMK" + convertno.ToString();
                    }
                    else if (_ProviderId == 45)
                    {
                        lblQRefNo.Text = "VRY" + convertno.ToString();
                    }
                    else if (_ProviderId == 46)
                    {
                        lblQRefNo.Text = "TMS" + convertno.ToString();
                    }
                    else if (_ProviderId == 50)
                    {
                        lblQRefNo.Text = "SCS" + convertno.ToString();
                    }
                    else if (_ProviderId == 51)
                    {
                        lblQRefNo.Text = "SMG" + convertno.ToString();
                    }
                    else if (_ProviderId == 58)
                    {
                        lblQRefNo.Text = "TVV" + convertno.ToString();
                    }
                    else if (_ProviderId == 65)
                    {
                        lblQRefNo.Text = "DPY" + convertno.ToString();
                    }
                    else if (_ProviderId == 66)
                    {
                        lblQRefNo.Text = "TPB" + convertno.ToString();
                    }
                }
                else
                {
                    lblQRefNo.Text = "GG" + _ProviderId.ToString() + convertno.ToString();
                }

                if (_dtProvider.Tables[3].Rows.Count > 0)
                {
                    ddlOccupation.Occupation = _dtProvider.Tables[3].Rows[0]["Occupation"].ToString();
                }
            }
            else
            {
                _redirectUrl = CE.Global.General.GetUrl("~/user/user-message", Page);
                Session["UMMSG"] = "CI,502";
                Response.Redirect(_redirectUrl);
            }
        }
        else
        {
            _redirectUrl = CE.Global.General.GetUrl("~/user/user-message", Page);
            Session["UMMSG"] = "CI,502";
            Response.Redirect(_redirectUrl);
        }
        LoadCarDrivers();
    }

    private void LoadDOB()
    {
        ddlDayDOB1.Items.Clear();
        ddlDayDOB2.Items.Clear();
        for (int _day = 1; _day <= 31; _day++)
        {
            ddlDayDOB1.Items.Add(new ListItem(_day.ToString("00"), _day.ToString("00")));
            ddlDayDOB2.Items.Add(new ListItem(_day.ToString("00"), _day.ToString("00")));
        }
        ddlDayDOB1.Items.Insert(0, new ListItem(Resources.General.Day, "-1"));
        ddlDayDOB2.Items.Insert(0, new ListItem(Resources.General.Day, "-1"));

        ddlYearDOB1.Items.Clear();
        ddlYearDOB2.Items.Clear();
        int _styr = CE.Global.General.GetUTCDateTime().Year - 18;
        int _endyr = _styr - 100;
        for (int _year = _styr; _year >= _endyr; _year--)
        {
            ddlYearDOB1.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
            ddlYearDOB2.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
        }
        ddlYearDOB1.Items.Insert(0, new ListItem(Resources.General.Year, "-1"));
        ddlYearDOB2.Items.Insert(0, new ListItem(Resources.General.Year, "-1"));
    }

    private void LoadCarDrivers()
    {
        CarDriverDB _cardriverdb = new CarDriverDB();
        _CarId = Convert.ToInt64(Session[General.CarId].ToString());
        if (Session[CE.Global.General.UserId] != null)
        {
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        }
        else
        {
            _UserId = 0;
        }
        DataTable _driverList = _cardriverdb.GetDriverList(_CarId, _UserId);
        if (_driverList.Rows.Count > 0)
        {
            lblDriverId1.Text = _driverList.Rows[0]["CarDriverId"].ToString();

            _dtDOB1 = Convert.ToDateTime(_driverList.Rows[0]["DOB"].ToString());
            ddlDayDOB1.Text = _dtDOB1.Day.ToString();
            ddlMonthDOB1.Text = _dtDOB1.Month.ToString();
            ddlYearDOB1.Text = _dtDOB1.Year.ToString();

            if (_driverList.Rows[0]["Surname"].ToString() != null && _driverList.Rows[0]["Surname"].ToString() != "")
            {
                txtDriverName1.Text = _driverList.Rows[0]["Surname"].ToString();
            }
        }
        if (_driverList.Rows.Count > 1)
        {
            lblDriverId2.Text = _driverList.Rows[1]["CarDriverId"].ToString();

            _dtDOB2 = Convert.ToDateTime(_driverList.Rows[1]["DOB"].ToString());
            ddlDayDOB2.Text = _dtDOB2.Day.ToString();
            ddlMonthDOB2.Text = _dtDOB2.Month.ToString();
            ddlYearDOB2.Text = _dtDOB2.Year.ToString();

            if (_driverList.Rows[1]["Surname"].ToString() != null && _driverList.Rows[1]["Surname"].ToString() != "")
            {
                txtDriverName2.Text = _driverList.Rows[1]["Surname"].ToString();
            }
        }

    }

    private bool UpdateDriverDetails()
    {
        bool _result = false;
        CarDriver _cardriver = new CarDriver();
        CarDriverDB _cardriverdb = new CarDriverDB();

        if (txtDriverCount.Text.Trim() != "0")
        {
            int _drivercount = Convert.ToInt32(txtDriverCount.Text.Trim());
            int _insertcount = 0;

            for (int i = 1; i <= _drivercount; i++)
            {
                _cardriver.StepId = 2;
                if (Session[CE.Global.General.UserId] != null)
                {
                    _cardriver.RerCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _cardriver.RerCEUserId = 0;
                }
                _cardriver.CECarId = Convert.ToInt64(Session[General.CarId].ToString());
                if (i == 1)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId1.Text.Trim());
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverName1.Text.Trim()));
                    _cardriver.DOB = _dtDOB1;
                    _cardriver.DrivingLicenseNumber = Server.HtmlEncode(General.ClearScriptTag(txtDrivingLicenseNumber1.Text.Trim()));
                    _cardriver.Status = "Active";
                    if (_cardriver.CarDriverId == 0)
                    {
                        _cardriver.StepId = 1;
                    }
                }
                else if (i == 2)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId2.Text.Trim());
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverName2.Text.Trim()));
                    _cardriver.DOB = _dtDOB2;
                    _cardriver.DrivingLicenseNumber = Server.HtmlEncode(General.ClearScriptTag(txtDrivingLicenseNumber2.Text.Trim()));
                    _cardriver.Status = "Active";
                    if (_cardriver.CarDriverId == 0)
                    {
                        _cardriver.StepId = 1;
                    }
                }
                _cardriver.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                if (_cardriverdb.Insert(_cardriver) > 0)
                {
                    _insertcount++;
                    CarPolicyDB _carpolicydb = new CarPolicyDB();
                    _carpolicydb.UpdateDriverCount(true, _insertcount, _cardriver.CECarId, _cardriver.RerCEUserId);
                    _carpolicydb = null;
                    _result = true;
                }
            }
            _cardriverdb = null;
            _cardriver = null;
        }
        return _result;
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("CI", Request, "Car Insurance Thaipaiboon proposal form.");
    }

    private void CheckValidation()
    {
        //ClearScriptTag
        txtName.Text = General.ClearScriptTag(txtName.Text);
        txtIdentificationNo.Text = General.ClearScriptTag(txtIdentificationNo.Text);
        //txtLicenseNo.Text = General.ClearScriptTag(txtLicenseNo.Text);
        txtBeneficiaryName.Text = General.ClearScriptTag(txtBeneficiaryName.Text);
        txtCarPlate.Text = General.ClearScriptTag(txtCarPlate.Text);
        //txtCarPlateProvince.Text = General.ClearScriptTag(txtCarPlateProvince.Text);
        txtPresentAddress.Text = General.ClearScriptTag(txtPresentAddress.Text);
        txtPostalCode.Text = General.ClearScriptTag(txtPostalCode.Text);
        txtMailingAddress.Text = General.ClearScriptTag(txtMailingAddress.Text);
        txtMailingPostalCode.Text = General.ClearScriptTag(txtMailingPostalCode.Text);
        txtEngineNumber.Text = General.ClearScriptTag(txtEngineNumber.Text);
        txtChassisNumber.Text = General.ClearScriptTag(txtChassisNumber.Text);
        txtHomeOfficeNo.Text = General.ClearScriptTag(txtHomeOfficeNo.Text);

        //HtmlEncode
        txtName.Text = Server.HtmlEncode(txtName.Text);
        txtIdentificationNo.Text = Server.HtmlEncode(txtIdentificationNo.Text);
        //txtLicenseNo.Text = Server.HtmlEncode(txtLicenseNo.Text);
        txtBeneficiaryName.Text = Server.HtmlEncode(txtBeneficiaryName.Text);
        txtCarPlate.Text = Server.HtmlEncode(txtCarPlate.Text);
        //txtCarPlateProvince.Text = Server.HtmlEncode(txtCarPlateProvince.Text);
        txtPresentAddress.Text = Server.HtmlEncode(txtPresentAddress.Text);
        txtPostalCode.Text = Server.HtmlEncode(txtPostalCode.Text);
        txtMailingAddress.Text = Server.HtmlEncode(txtMailingAddress.Text);
        txtMailingPostalCode.Text = Server.HtmlEncode(txtMailingPostalCode.Text);
        txtEngineNumber.Text = Server.HtmlEncode(txtEngineNumber.Text);
        txtChassisNumber.Text = Server.HtmlEncode(txtChassisNumber.Text);
        txtHomeOfficeNo.Text = Server.HtmlEncode(txtHomeOfficeNo.Text);
    }

    private void ChangeRequiredFieldValidation(WebControl ctl, RequiredFieldValidator rfv, string strValidation)
    {
        if (rfv.Enabled && rfv.ValidationGroup == strValidation)
        {
            rfv.Validate();
            if (rfv.IsValid == false)
            {
                ctl.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                ctl.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ctl.ControlStyle.CssClass = "proposal-fields";
        }
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        #region Proposal Details
        //Name
        if (rfvName.Enabled && rfvName.ValidationGroup == strValidationGroup)
        {
            rfvName.Validate();
            if (rfvName.IsValid == false)
            {
                txtName.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                txtName.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "proposal-fields";
        }

        if (revName.Enabled && revName.ValidationGroup == strValidationGroup)
        {
            if (rfvName.IsValid)
            {
                revName.Validate();
                if (revName.IsValid == false)
                {
                    txtName.ControlStyle.CssClass = "proposal-fields validationError";
                }
                else
                {
                    txtName.ControlStyle.CssClass = "proposal-fields";
                }
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "proposal-fields";
        }

        //IdentificationNo
        if (rfvIdentificationNo.Enabled && rfvIdentificationNo.ValidationGroup == strValidationGroup)
        {
            rfvIdentificationNo.Validate();
            if (rfvIdentificationNo.IsValid == false)
            {
                txtIdentificationNo.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                txtIdentificationNo.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            txtIdentificationNo.ControlStyle.CssClass = "proposal-fields";
        }

        if (revIdentificationNo.Enabled && revIdentificationNo.ValidationGroup == strValidationGroup)
        {
            if (rfvIdentificationNo.IsValid)
            {
                revIdentificationNo.Validate();
                if (revIdentificationNo.IsValid == false)
                {
                    txtIdentificationNo.ControlStyle.CssClass = "proposal-fields validationError";
                }
                else
                {
                    txtIdentificationNo.ControlStyle.CssClass = "proposal-fields";
                }
            }
        }
        else
        {
            txtIdentificationNo.ControlStyle.CssClass = "proposal-fields";
        }
        //Applicant's Occupation
        ddlOccupation.ChangeValidationEffectServerSide(strValidationGroup);
        //Applicant's Contact No
        txtContactNo.ChangeValidationEffectServerSide(strValidationGroup);
        //Applicant's Office No
        //txtOfficePhoneNo.ChangeValidationEffectServerSide(strValidationGroup);

        //BeneficiaryName
        if (rfvBeneficiaryName.Enabled && rfvBeneficiaryName.ValidationGroup == strValidationGroup)
        {
            rfvBeneficiaryName.Validate();
            if (rfvBeneficiaryName.IsValid == false)
            {
                txtBeneficiaryName.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                txtBeneficiaryName.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            txtBeneficiaryName.ControlStyle.CssClass = "proposal-fields";
        }

        if (revBeneficiaryName.Enabled && revBeneficiaryName.ValidationGroup == strValidationGroup)
        {
            if (rfvBeneficiaryName.IsValid)
            {
                revBeneficiaryName.Validate();
                if (revBeneficiaryName.IsValid == false)
                {
                    txtBeneficiaryName.ControlStyle.CssClass = "proposal-fields validationError";
                }
                else
                {
                    txtBeneficiaryName.ControlStyle.CssClass = "proposal-fields";
                }
            }
        }
        else
        {
            txtBeneficiaryName.ControlStyle.CssClass = "proposal-fields";
        }

        //CarPlate
        if (rfvCarPlate.Enabled && rfvCarPlate.ValidationGroup == strValidationGroup)
        {
            rfvCarPlate.Validate();
            if (rfvCarPlate.IsValid == false)
            {
                txtCarPlate.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                txtCarPlate.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            txtCarPlate.ControlStyle.CssClass = "";
        }

        //CarPlate Province
        if (rfvCarPlateProvince.Enabled && rfvCarPlateProvince.ValidationGroup == strValidationGroup)
        {
            rfvCarPlateProvince.Validate();
            if (rfvCarPlateProvince.IsValid == false)
            {
                ddlCarPlateProvince.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                ddlCarPlateProvince.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlCarPlateProvince.ControlStyle.CssClass = "proposal-fields";
        }

        //PresentAddress
        if (rfvPresentAddress.Enabled && rfvPresentAddress.ValidationGroup == strValidationGroup)
        {
            rfvPresentAddress.Validate();
            if (rfvPresentAddress.IsValid == false)
            {
                txtPresentAddress.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                txtPresentAddress.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            txtPresentAddress.ControlStyle.CssClass = "proposal-fields";
        }

        //Sub District
        if (rfvSubDistrict.Enabled && rfvSubDistrict.ValidationGroup == strValidationGroup)
        {
            rfvSubDistrict.Validate();
            if (rfvSubDistrict.IsValid == false)
            {
                ddlSubDistrict.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                ddlSubDistrict.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlSubDistrict.ControlStyle.CssClass = "proposal-fields";
        }

        //District
        if (rfvDistrict.Enabled && rfvDistrict.ValidationGroup == strValidationGroup)
        {
            rfvDistrict.Validate();
            if (rfvDistrict.IsValid == false)
            {
                ddlDistrict.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                ddlDistrict.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlDistrict.ControlStyle.CssClass = "proposal-fields";
        }

        //Province
        if (rfvProvince.Enabled && rfvProvince.ValidationGroup == strValidationGroup)
        {
            rfvProvince.Validate();
            if (rfvProvince.IsValid == false)
            {
                ddlProvince.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                ddlProvince.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlProvince.ControlStyle.CssClass = "proposal-fields";
        }

        //Postal Code
        if (rfvPostalCode.Enabled && rfvPostalCode.ValidationGroup == strValidationGroup)
        {
            rfvPostalCode.Validate();
            if (rfvPostalCode.IsValid == false)
            {
                txtPostalCode.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                txtPostalCode.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            txtPostalCode.ControlStyle.CssClass = "proposal-fields";
        }

        if (revPostalCode.Enabled && revPostalCode.ValidationGroup == strValidationGroup)
        {
            if (rfvPostalCode.IsValid)
            {
                revPostalCode.Validate();
                if (revPostalCode.IsValid == false)
                {
                    txtPostalCode.ControlStyle.CssClass = "proposal-fields validationError";
                }
                else
                {
                    txtPostalCode.ControlStyle.CssClass = "proposal-fields";
                }
            }
        }
        else
        {
            txtPostalCode.ControlStyle.CssClass = "proposal-fields";
        }
        #endregion

        #region MailingAddress
        ChangeRequiredFieldValidation(txtMailingAddress, rfvMailingAddress, strValidationGroup);
        ChangeRequiredFieldValidation(ddlMailingSubDistrict, rfvMailingSubDistrict, strValidationGroup);
        ChangeRequiredFieldValidation(ddlMailingDistrict, rfvMailingDistrict, strValidationGroup);
        ChangeRequiredFieldValidation(ddlMailingProvince, rfvMailingProvince, strValidationGroup);
        ChangeRequiredFieldValidation(txtMailingPostalCode, rfvMailingPostalCode, strValidationGroup);
        if (revMailingPostalCode.Enabled && revMailingPostalCode.ValidationGroup == strValidationGroup)
        {
            if (rfvMailingPostalCode.IsValid)
            {
                revMailingPostalCode.Validate();
                if (revMailingPostalCode.IsValid == false)
                {
                    txtMailingPostalCode.ControlStyle.CssClass = "proposal-fields validationError";
                }
                else
                {
                    txtMailingPostalCode.ControlStyle.CssClass = "proposal-fields";
                }
            }
        }
        else
        {
            txtMailingPostalCode.ControlStyle.CssClass = "proposal-fields";
        }
        #endregion

        #region Payment Mode

        //PaymentType
        if (rfvPaymentType.Enabled && rfvPaymentType.ValidationGroup == strValidationGroup)
        {
            rfvPaymentType.Validate();
            if (rfvPaymentType.IsValid == false)
            {
                lblBankIn.ControlStyle.CssClass = "validationError";
                lblCreditCard.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblBankIn.ControlStyle.CssClass = "";
                lblCreditCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblBankIn.ControlStyle.CssClass = "";
            lblCreditCard.ControlStyle.CssClass = "";
        }

        #endregion

        #region Drivers
        //Driver 1 **************************************************************
        //Name
        if (rfvDriverName1.Enabled && rfvDriverName1.ValidationGroup == strValidationGroup)
        {
            rfvDriverName1.Validate();
            if (rfvDriverName1.IsValid == false)
            {
                txtDriverName1.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                txtDriverName1.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            txtDriverName1.ControlStyle.CssClass = "proposal-fields";
        }

        //DOB Day1
        if (rfvDayDOB1.Enabled && rfvDayDOB1.ValidationGroup == strValidationGroup)
        {
            rfvDayDOB1.Validate();
            if (rfvDayDOB1.IsValid == false)
            {
                ddlDayDOB1.ControlStyle.CssClass = "proposal-combo validationError";
            }
            else
            {
                ddlDayDOB1.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlDayDOB1.ControlStyle.CssClass = "proposal-fields";
        }

        //DOB Month1
        if (rfvMonthDOB1.Enabled && rfvMonthDOB1.ValidationGroup == strValidationGroup)
        {
            rfvMonthDOB1.Validate();
            if (rfvMonthDOB1.IsValid == false)
            {
                ddlMonthDOB1.ControlStyle.CssClass = "proposal-combo validationError";
            }
            else
            {
                ddlMonthDOB1.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlMonthDOB1.ControlStyle.CssClass = "proposal-fields";
        }

        //DOB Year1
        if (rfvYearDOB1.Enabled && rfvYearDOB1.ValidationGroup == strValidationGroup)
        {
            rfvYearDOB1.Validate();
            if (rfvYearDOB1.IsValid == false)
            {
                ddlYearDOB1.ControlStyle.CssClass = "proposal-combo validationError";
            }
            else
            {
                ddlYearDOB1.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlYearDOB1.ControlStyle.CssClass = "proposal-fields";
        }

        //Driver 2 **************************************************************
        //Name
        if (rfvDriverName2.Enabled && rfvDriverName2.ValidationGroup == strValidationGroup)
        {
            rfvDriverName2.Validate();
            if (rfvDriverName2.IsValid == false)
            {
                txtDriverName2.ControlStyle.CssClass = "proposal-fields validationError";
            }
            else
            {
                txtDriverName2.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            txtDriverName2.ControlStyle.CssClass = "proposal-fields";
        }

        //DOB Day1
        if (rfvDayDOB2.Enabled && rfvDayDOB2.ValidationGroup == strValidationGroup)
        {
            rfvDayDOB2.Validate();
            if (rfvDayDOB2.IsValid == false)
            {
                ddlDayDOB2.ControlStyle.CssClass = "proposal-combo validationError";
            }
            else
            {
                ddlDayDOB2.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlDayDOB2.ControlStyle.CssClass = "proposal-fields";
        }

        //DOB Month2
        if (rfvMonthDOB2.Enabled && rfvMonthDOB2.ValidationGroup == strValidationGroup)
        {
            rfvMonthDOB2.Validate();
            if (rfvMonthDOB2.IsValid == false)
            {
                ddlMonthDOB2.ControlStyle.CssClass = "proposal-combo validationError";
            }
            else
            {
                ddlMonthDOB2.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlMonthDOB2.ControlStyle.CssClass = "proposal-fields";
        }

        //DOB Year2
        if (rfvYearDOB2.Enabled && rfvYearDOB2.ValidationGroup == strValidationGroup)
        {
            rfvYearDOB2.Validate();
            if (rfvYearDOB2.IsValid == false)
            {
                ddlYearDOB2.ControlStyle.CssClass = "proposal-combo validationError";
            }
            else
            {
                ddlYearDOB2.ControlStyle.CssClass = "proposal-fields";
            }
        }
        else
        {
            ddlYearDOB2.ControlStyle.CssClass = "proposal-fields";
        }


        #endregion

    }

    private void EnableCreditCardControls(bool isEnable)
    {
    }

    private void EnableDriverPanels()
    {
        if (rdoNoAddDriver.Checked)
        {
            txtDriverCount.Text = "0";
            pnlDriverDetails.Visible = false;
            pnlDriver1.Visible = false;
            pnlDriver2.Visible = false;

            ValidateDriver1(false);
            ValidateDriver2(false);
        }
        else if (rdoYesAddDriver.Checked)
        {
            txtDriverCount.Text = ddlDriverCount.Text;
            if (txtDriverCount.Text.Trim() == "1")
            {
                pnlDriverDetails.Visible = true;
                pnlDriver1.Visible = true;
                pnlDriver2.Visible = false;

                ValidateDriver1(true);
                ValidateDriver2(false);
            }
            else if (txtDriverCount.Text.Trim() == "2")
            {
                pnlDriverDetails.Visible = true;
                pnlDriver1.Visible = true;
                pnlDriver2.Visible = true;

                ValidateDriver1(true);
                ValidateDriver2(true);
            }
        }

    }

    private void ValidateDriver1(bool OnOff)
    {
        rfvDriverName1.Enabled = OnOff;
        rfvDayDOB1.Enabled = OnOff;
        rfvMonthDOB1.Enabled = OnOff;
        rfvYearDOB1.Enabled = OnOff;
    }

    private void ValidateDriver2(bool OnOff)
    {
        rfvDriverName2.Enabled = OnOff;
        rfvDayDOB2.Enabled = OnOff;
        rfvMonthDOB2.Enabled = OnOff;
        rfvYearDOB2.Enabled = OnOff;
    }

    //lee08092014
    # region "Address"
    private DataTable GetProvince()
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable();
        SortedList _sPara = new SortedList();
        _dt = _db.GetDataTableBySP("sprocTHProvinceSelectItemList", _sPara);
        _dt.DefaultView.Sort = Resources.CarInsuranceProposal.ProvinceLang;
        _db = null;
        return _dt;
    }

    private DataTable GetDistrict(string provinceid)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable();
        SortedList _sPara = new SortedList();
        _sPara.Add("@ProvinceID", provinceid);
        _dt = _db.GetDataTableBySP("sprocTHDistrictSelectItemList", _sPara);
        _dt.DefaultView.Sort = Resources.CarInsuranceProposal.ProvinceLang;
        _db = null;
        return _dt;
    }

    private DataTable GetPostCode(string provinceid, string districtid)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable();
        SortedList _sPara = new SortedList();
        _sPara.Add("@ProvinceID", provinceid);
        _sPara.Add("@DistrictID", districtid);
        _dt = _db.GetDataTableBySP("sprocTHPostCodeSelectItemList", _sPara);
        _db = null;
        return _dt;
    }

    private void BindDdlCarPlateProvince()
    {
        DataTable _dt = new DataTable();
        _dt = GetProvince();

        if (_dt != null && _dt.Rows.Count > 0)
        {
            ddlCarPlateProvince.Items.Clear();
            ddlCarPlateProvince.DataSource = _dt;
            ddlCarPlateProvince.DataTextField = Resources.CarInsuranceProposal.ProvinceLang;
            ddlCarPlateProvince.DataValueField = "ProvinceID";
            ddlCarPlateProvince.DataBind();
            ddlCarPlateProvince.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        else
        {
            ddlCarPlateProvince.Items.Clear();
            ddlCarPlateProvince.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }

        _dt = null;
    }

    private void BindProvince()
    {
        DataTable _dt = new DataTable();
        _dt = GetProvince();

        if (_dt != null && _dt.Rows.Count > 0)
        {
            ddlProvince.Items.Clear();
            ddlProvince.DataSource = _dt;
            ddlProvince.DataTextField = Resources.CarInsuranceProposal.ProvinceLang;
            ddlProvince.DataValueField = "ProvinceID";
            ddlProvince.DataBind();
            ddlProvince.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        else
        {
            ddlProvince.Items.Clear();
            ddlProvince.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }

        _dt = null;
    }

    private void BindDdlMailingProvince()
    {
        DataTable _dt = new DataTable();
        _dt = GetProvince();

        if (_dt != null && _dt.Rows.Count > 0)
        {
            ddlMailingProvince.Items.Clear();
            ddlMailingProvince.DataSource = _dt;
            ddlMailingProvince.DataTextField = Resources.CarInsuranceProposal.ProvinceLang;
            ddlMailingProvince.DataValueField = "ProvinceID";
            ddlMailingProvince.DataBind();
            ddlMailingProvince.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        else
        {
            ddlMailingProvince.Items.Clear();
            ddlMailingProvince.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }

        _dt = null;
    }

    private void BindDistrict()
    {
        DataTable _dt = new DataTable();
        _dt = GetDistrict(ddlProvince.SelectedValue);

        if (_dt != null && _dt.Rows.Count > 0)
        {
            ddlDistrict.Items.Clear();
            ddlDistrict.DataSource = _dt;
            ddlDistrict.DataTextField = Resources.CarInsuranceProposal.ProvinceLang;
            ddlDistrict.DataValueField = "DistrictID";
            ddlDistrict.DataBind();
            ddlDistrict.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
            ddlDistrict.Items.Insert(_dt.Rows.Count + 1, new ListItem(Resources.CarInsurance.Others, "999"));
        }
        else
        {
            ddlDistrict.Items.Clear();
            ddlDistrict.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }

        _dt = null;
    }

    private void BindDdlMailingDistrict()
    {
        DataTable _dt = new DataTable();
        _dt = GetDistrict(ddlMailingProvince.SelectedValue);

        if (_dt != null && _dt.Rows.Count > 0)
        {
            ddlMailingDistrict.Items.Clear();
            ddlMailingDistrict.DataSource = _dt;
            ddlMailingDistrict.DataTextField = Resources.CarInsuranceProposal.ProvinceLang;
            ddlMailingDistrict.DataValueField = "DistrictID";
            ddlMailingDistrict.DataBind();
            ddlMailingDistrict.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
            ddlMailingDistrict.Items.Insert(_dt.Rows.Count + 1, new ListItem(Resources.CarInsurance.Others, "999"));
        }
        else
        {
            ddlMailingDistrict.Items.Clear();
            ddlMailingDistrict.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }

        _dt = null;
    }

    protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlProvince.SelectedValue != "-1")
        {
            ddlDistrict.Style.Add("width", "240px");
            BindDistrict();
        }
        else
        {
            ddlDistrict.Items.Clear();
            ddlDistrict.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        txtPostalCode.Text = "";
    }

    protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlDistrict.SelectedValue != "-1")
        {
            if (ddlDistrict.SelectedValue != "999")
            {
                ddlDistrict.Style.Add("width", "240px");
                DataTable _dt = new DataTable();
                _dt = GetPostCode(ddlProvince.SelectedValue, ddlDistrict.SelectedValue);
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    txtPostalCode.Text = _dt.Rows[0]["PostCode"].ToString();
                }

            }
            else
            {

                ddlDistrict.Style.Add("width", "95px");
                txtPostalCode.Text = "";

            }
        }
        else
            txtPostalCode.Text = "";
    }

    protected void ddlMailingProvince_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlMailingProvince.SelectedValue != "-1")
        {
            ddlMailingDistrict.Style.Add("width", "240px");
            BindDdlMailingDistrict();
        }
        else
        {
            ddlMailingDistrict.Items.Clear();
            ddlMailingDistrict.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        txtMailingPostalCode.Text = "";
    }

    protected void ddlMailingDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlMailingDistrict.SelectedValue != "-1")
        {
            if (ddlMailingDistrict.SelectedValue != "999")
            {
                ddlMailingDistrict.Style.Add("width", "240px");
                DataTable _dt = new DataTable();
                _dt = GetPostCode(ddlMailingProvince.SelectedValue, ddlMailingDistrict.SelectedValue);
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    txtMailingPostalCode.Text = _dt.Rows[0]["PostCode"].ToString();
                }
            }
            else
            {

                ddlMailingDistrict.Style.Add("width", "95px");
                txtMailingPostalCode.Text = "";
            }
        }
        else
            txtMailingPostalCode.Text = "";
    }

    #endregion

    private bool CheckConfirmStatus()
    {
        bool _retValue = false;
        Int64 _CarId = 0;
        ThaipaiboonCarMoreDetailDB _Thaipaibooncarmoredetaildb = new ThaipaiboonCarMoreDetailDB();
        if (Session[General.CarId] != null)
        {
            _CarId = Convert.ToInt64(Session[General.CarId].ToString());
        }
        Int64 _checkResult = _Thaipaibooncarmoredetaildb.CheckConfirmStatus(_CarId, "CI");
        if (_checkResult > 0)
        {
            _retValue = true;
        }
        else
        {
            _retValue = false;
        }

        return _retValue;
    }

    private Int64 GetOrderRefNoId()
    {
        Int64 _retValue = 0;
        Int64 _OrderId = 0;
        ThaipaiboonCarMoreDetailDB _Thaipaibooncarmoredetaildb = new ThaipaiboonCarMoreDetailDB();
        if (Session[General.CarId] != null)
        {
            _CarId = Convert.ToInt64(Session[General.CarId].ToString());
        }
        MyDatabase _db = new MyDatabase();
        string strSql = "SELECT OrderRefNoId FROM [tblCarMoreDetail_TPB] ORDER BY CECarMoreDetailId DESC ";
        object _result = _db.ExecuteScalarSqlStatement(strSql);
        if (_result != null)
        {
            _OrderId = Convert.ToInt64(_result.ToString());
        }
        _retValue = _OrderId + 1;

        return _retValue;
    }

    private void ProposalNotification()
    {
        string _strMailActive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsMailActive");
        if (_strMailActive == "1")
        {
            string _strSql, _providerName, _ToEmail, _CCEmail, _BCCEmail, _Date, _Time, _InsuranceName, _RefNo;
            MyDatabase _db = new MyDatabase();
            DataTable _dtProvider = new DataTable();
            DataTable _dtInsurance = new DataTable();
            _Date = "";
            _Time = "";
            _RefNo = "";
            _strSql = "";
            _providerName = "";
            _ToEmail = "";
            _CCEmail = "";
            _BCCEmail = "";
            _InsuranceName = Resources.WelcomeEmail.CarInsurance; //"Car Insurance";

            _ToEmail = Session[General.UserEmail].ToString();
            if (Session[General.ProviderCompanyId] != null && Session[General.CarId] != null)
            {
                _ProviderId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
                _CarId = Convert.ToInt64(Session[General.CarId].ToString());
            }
            _strSql = "SELECT [CompanyName], [Email1], [PhoneNo1] FROM tblProviderCompany WHERE ProviderCompanyId = " + _ProviderId.ToString();

            _dtProvider = _db.GetDataTable(_strSql);
            if (_dtProvider.Rows.Count > 0)
            {
                _providerName = _dtProvider.Rows[0]["CompanyName"].ToString();
                _CCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.CI_CC");
                _BCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.CI_BCC");
            }
            _strSql = "";
            _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
            _strSql += " FROM  tblCarMoreDetail_TPB WHERE CECarId = " + _CarId.ToString() + " ORDER BY ModifiedDate DESC";
            _dtInsurance = _db.GetDataTable(_strSql);
            if (_dtInsurance.Rows.Count > 0)
            {
                _Date = _dtInsurance.Rows[0]["Date"].ToString();
                _Time = _dtInsurance.Rows[0]["Time"].ToString();
            }
            _RefNo = lblQRefNo.Text.Trim();
            if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
            {
                //MailManagerTH.SendCarProposalNotificationToUser(_providerName, _ToEmail, _CCEmail, _BCCEmail, _InsuranceName, _Date, _Time, _RefNo, "BI");
                //MailManagerTH.SendCarProposalToUser(_providerName, _ToEmail, _CCEmail, _BCCEmail, _InsuranceName, _Date, _Time, _RefNo);

                SendProposalToUserNEW(Session[General.CarResultId].ToString());
            }
        }
    }

    public string GetOrderRefNo()
    {
        Int64 CarId = 0;
        if (Session[CE.Global.General.CarId] != null)
            CarId = Convert.ToInt64(Session[CE.Global.General.CarId].ToString());
        string _result = "";
        string _onoffline = "1";
        string _firstno = General.GetUTCDateTime().ToString("yy") + General.GetUTCDateTime().Month.ToString("00") + General.GetUTCDateTime().Day.ToString("00") +
                          General.GetUTCDateTime().Hour.ToString("00") + General.GetUTCDateTime().Minute.ToString("00");
        _result = _firstno + _onoffline + CarId.ToString("000000000");
        return _result;
    }

    private string GetOrderRefNo_Old()
    {
        string _OrderNo = General.GetUTCDateTime().ToString("yy");
        string _RandomNo = "";
        int _len = Session[CE.Global.General.CarId].ToString().Length;
        int _randomlen = 9 - _len;
        Random random = new Random();
        for (int i = 0; i < _randomlen; i++)
        {
            _RandomNo += random.Next(0, 9).ToString();
        }
        _OrderNo = _OrderNo + _len + _RandomNo + Session[CE.Global.General.CarId].ToString();
        return _OrderNo;
    }

    protected void csvCreditCardValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        bool _status = true;
    }

    protected void csvCCExpiredValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
    }

    private void LoadCardExpiryMonth()
    {
    }

    private void LoadCardExpiryYear()
    {
    }
    private bool SendProposalToUserNEW(string CITempResultId)
    {
        Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());
        CE.User.Profile usrprofile = new Profile();
        ProfileDB usrprofiledb = new ProfileDB();

        usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

        string userfirstname = "";

        if (usrprofile != null)
        {
            userfirstname = usrprofile.FirstName;
        }

        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        string _Premium = "";
        string _Gender = "";
        string _DOB = "";
        string _Occupation = "";
        string _InsuranceType = "";
        string _NCB = "";

        string _GarageType = "";
        string _CarYear = "";
        string _CarMakeModel = "";
        string _CarType = "";
        string _CarPlate = "";
        string _NameDriver = "";
        string _Name = "";
        string _PolicyStartDate = "";
        string _isCTPL = "No";
        string _CTPL = "";

        Int64 _companyId = 0;

        System.Data.DataTable _dtSeletectItem = new System.Data.DataTable("SelectedResultItem");
        _dtSeletectItem = _db.GetDataTable("Select * from tblCarInsuranceSelectItemTH WHERE CarId = " + _carId.ToString());
        if (_dtSeletectItem != null && _dtSeletectItem.Rows.Count > 0)
        {
            _companyId = Convert.ToInt64(_dtSeletectItem.Rows[0]["ProviderCompanyId"].ToString());
            _Premium = Convert.ToSingle(_dtSeletectItem.Rows[0]["AnnualPremium"].ToString()).ToString("#.00");
        }
        CarInsuranceCompletedItemDB _carinsurancecompleteditemdb = new CarInsuranceCompletedItemDB();
        _dsInsurance = _carinsurancecompleteditemdb.GetCarInsuranceCompletedItem(_carId, _companyId);
        if (_dsInsurance != null && _dsInsurance.Tables[0].Rows.Count > 0)
        {
            _Gender = _dsInsurance.Tables[0].Rows[0]["Gender"].ToString() == "Male" ? Resources.CarInsurance.Male : Resources.CarInsurance.Female;
            _DOB = Convert.ToDateTime(_dsInsurance.Tables[0].Rows[0]["DOB"]).ToString("dd-MMM-yyyy");
            if (CE.Global.General.SetCulture() == "th-TH")
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["THOccupation"].ToString();
            }
            else
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["ENOccupation"].ToString();
            }
            //lblInsuranceType.Text = _dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString();
            switch (_dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString())
            {
                case "Class 1":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOne;
                    _NCB = _dsInsurance.Tables[0].Rows[0]["NCB"].ToString();
                    break;
                case "Class 1 (Low Cost)":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOneLowCost;
                    _NCB = "N/A";
                    break;
                case "Class 2+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    _NCB = "N/A";
                    break;
                case "Class 3+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThreePlus;
                    _NCB = "N/A";
                    break;
                case "Class 3":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThree;
                    _NCB = "N/A";
                    break;
            }



            _GarageType = _dsInsurance.Tables[0].Rows[0]["GarageType"].ToString() == "Authorized" ? Resources.CarInsurance.Garage_Authorized : Resources.CarInsurance.Garage_Dealer;
            _CarYear = _dsInsurance.Tables[0].Rows[0]["CarModelYear"].ToString();
            _CarMakeModel = _dsInsurance.Tables[0].Rows[0]["MakeModelDesc"].ToString();
            _CarType = _dsInsurance.Tables[0].Rows[0]["VehicleType"].ToString() == "Private Use" ? Resources.CarInsurance.VehicleType_Private : Resources.CarInsurance.VehicleType_Commercial;
            //_CarPlate = _dsInsurance.Tables[0].Rows[0]["RedPlate"].ToString();
            //lblSumInsured.Text = Convert.ToSingle(_dsInsurance.Tables[0].Rows[0]["SumInsured"]).ToString("#,###") + " " + Resources.CarInsurance.Baht;
            //lblProvinceofRegistration.Text = _dsInsurance.Tables[0].Rows[0]["ProvinceRegistration"].ToString() == "Bangkok Metro Area" ? Resources.CarInsurance.Province_BKK : Resources.CarInsurance.Province_UPC;
            //lblAnyClaim.Text = _dsInsurance.Tables[0].Rows[0]["AnyClaim"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesHave : Resources.CarInsurance.Option_NoHave;
            //lblNCB.Text = _dsInsurance.Tables[0].Rows[0]["NCB"].ToString() + "%";
            _NameDriver = _dsInsurance.Tables[0].Rows[0]["Driver"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesSpecify : Resources.CarInsurance.Option_NoSpecify;

            if (_dsInsurance.Tables[1].Rows.Count > 0)
            {
                //    lblInsurer.Text = GetInsurer(_companyId);
                //    lblAnnualPremium.Text = Convert.ToSingle(_dsInsurance.Tables[1].Rows[0]["AnnualPremium"]).ToString("#,###.00") + " " + Resources.CarInsurance.Baht;
                //    lblCTPL.Text = _dsInsurance.Tables[1].Rows[0]["CTPL"].ToString() == "Yes" ? Resources.CarInsurance.Option_Yes : Resources.CarInsurance.Option_No;
                //    lblCTPLAmount.Text = Convert.ToSingle(_dsInsurance.Tables[1].Rows[0]["CTPLAmount"]).ToString("#.00") + " " + Resources.CarInsurance.Baht;
                //    lblPackage.Text = _dsInsurance.Tables[1].Rows[0]["CoverTypeDesc"].ToString();

                //    lblContactNo.Text = String.Format("{0:0##-###-####}", Convert.ToInt32(_dsInsurance.Tables[1].Rows[0]["ContactNo"]));
                //    lblVehicleNo.Text = _dsInsurance.Tables[1].Rows[0]["VehicleNo"].ToString();
                //    lblEngineNo.Text = _dsInsurance.Tables[1].Rows[0]["EngineNo"].ToString();
                //    lblChassisNo.Text = _dsInsurance.Tables[1].Rows[0]["ChassisNo"].ToString();
                //    lblVehicleColor.Text = _dsInsurance.Tables[1].Rows[0]["VehicleColor"].ToString();
                //    lblVehicleProvince.Text = _dsInsurance.Tables[1].Rows[0]["VehicleProvince"].ToString();

                _CarPlate = _dsInsurance.Tables[1].Rows[0]["VehicleNo"].ToString();
                if (_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"] != DBNull.Value)
                {
                    _PolicyStartDate = Convert.ToDateTime(_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"]).ToString("dd-MMM-yyyy");
                }
                _Name = _dsInsurance.Tables[1].Rows[0]["Name"].ToString();
                _refNo = _dsInsurance.Tables[1].Rows[0]["QuoteRefNo"].ToString();

                _isCTPL = _dsInsurance.Tables[1].Rows[0]["CTPL"].ToString();
                _CTPL = _dsInsurance.Tables[1].Rows[0]["CTPLAmount"].ToString();
            }
            //lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : " + _refNo + " - " + Resources.CarInsurance.CarInsuranceList + " " + lblCarMakeModel.Text;
        }

        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

        string _emailTo = Session[General.UserEmail].ToString();
        //string _emailTo = "sophon.vorasitchai@comparexpress.com";
        string _customername = Session[General.UserName].ToString();
        string _emailSubject = "<Online> - " + Resources.EmailMessage.Subject; // "Your Car Insurance Quotes on CompareXpress(Thailand)";
        string _mailBody = "";
        string domainUrl = "";
        Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());
        domainUrl = "http://" + myUri.Host;
        if (_strCXLive == "0")
        {
            domainUrl = "http://test.newgluaygluay.com.gluaygluay.info";
        }

        #region "Mail Body"

        #region Header
        _mailBody = "<html>";
        _mailBody += "<head>";
        _mailBody += "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />";
        _mailBody += "<title>GluayGluay</title>";
        _mailBody += "<style>";

        _mailBody += ".body {";
        _mailBody += "margin-left: 0px;";
        _mailBody += "margin-top: 0px;";
        _mailBody += "margin-right: 0px;";
        _mailBody += "margin-bottom: 0px;";
        _mailBody += "font-family: Arial, sans-serif;";
        _mailBody += "font-size: 14px;";
        _mailBody += "color: #000000;";
        _mailBody += "background-repeat: repeat-x;";
        _mailBody += "background-color: #fff;";
        _mailBody += "text-decoration: none;}";

        _mailBody += "</style>";
        _mailBody += "</head>";
        #endregion

        _mailBody += "<body class='body'>";
        _mailBody += "<table style='font-size:14px;' width='800' border='0' align='center' cellpadding='0' cellspacing='0'>";
        _mailBody += "<tr>";
        _mailBody += "<td height='1474' valign='top'>";
        _mailBody += "<table width='800' height='100' border='0' cellspacing='0' cellpadding='0'>";
        _mailBody += "<tr>";
        _mailBody += "<td><span class='email-banner'><img src='" + domainUrl + "/images/email-header.jpg' width='800' height='100' alt='' /></span></td>";
        _mailBody += "</tr>";
        _mailBody += "</table>";
        _mailBody += "<br />";

        #region Thank you
        _mailBody += "<table style='line-height: 20px;' width='329' border='0' cellspacing='0' cellpadding='0'>";
        _mailBody += "<tr>";
        _mailBody += "<td width='329'><strong>" + Resources.Proposal.OrderConfirmation + "</strong></td>";
        _mailBody += "</tr>";
        _mailBody += "<tr>";
        _mailBody += " <td>" + Resources.Proposal.ThankYou + "</td>";
        _mailBody += "</tr>";
        _mailBody += "</table>";
        _mailBody += "<br />";
        #endregion

        #region Car Details
        _mailBody += "<table width='700' border='0' cellspacing='0' cellpadding='0'>";
        _mailBody += "<tr>";
        _mailBody += "<td height='146' valign='top' bgcolor='#C1C1C1'>";
        _mailBody += "<br />";
        _mailBody += "<table width='800' border='0' cellspacing='1' cellpadding='1'>";
        _mailBody += "<tr>";
        _mailBody += "<td height='26' colspan='4' bgcolor='#E7E7E7'>";
        _mailBody += "<span style='font-size: 14px; font-weight: bold; padding-left: 10px; padding-bottom: 5px;";
        _mailBody += "padding-top: 5px;'>" + Resources.Proposal.OrderNo + " " + _refNo + "</span>";
        _mailBody += "</td>";
        _mailBody += "</tr>";
        _mailBody += "<tr>";
        _mailBody += "<td width='150' height='25' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += Resources.Proposal.NameLastname + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td width='363' height='25' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += _Name + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td width='148' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += Resources.Proposal.OrderDate + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td width='126' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += General.GetUTCDateTime().ToString("dd/MMM/yyyy") + "</span>";
        _mailBody += "</td>";
        _mailBody += "</tr>";
        _mailBody += "<tr>";
        _mailBody += "<td height='25' bgcolor='#E7E7E7'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += Resources.Proposal.CarYear + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td height='25' bgcolor='#E7E7E7'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += _CarYear + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td bgcolor='#E7E7E7'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += Resources.Proposal.LicensePlateNo + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td bgcolor='#E7E7E7'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += _CarPlate + "</span>";
        _mailBody += "</td>";
        _mailBody += "</tr>";
        _mailBody += "<tr>";
        _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += Resources.Proposal.MakeModel + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td height='30' colspan='3' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += _CarMakeModel + "</span>";
        _mailBody += "</td>";
        _mailBody += "</tr>";
        _mailBody += "<tr>";
        _mailBody += "<td height='25' bgcolor='#E7E7E7'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += Resources.Proposal.GarageType + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td bgcolor='#E7E7E7'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += _GarageType + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td bgcolor='#E7E7E7'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += Resources.Proposal.NamedDrivers + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td bgcolor='#E7E7E7'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += _NameDriver + "</span>";
        _mailBody += "</td>";
        _mailBody += "</tr>";
        _mailBody += "<tr>";
        _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += Resources.Proposal.PolicyStartDate + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += _PolicyStartDate + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += Resources.Proposal.NCB + "</span>";
        _mailBody += "</td>";
        _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
        _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
        _mailBody += _NCB + "</span>";
        _mailBody += "</td>";
        _mailBody += "</tr>";
        _mailBody += "</table>";
        _mailBody += "</td>";
        _mailBody += "</tr>";
        _mailBody += "</table>";
        _mailBody += "<br />";
        #endregion

        //Sakthi on 18 Jan 2012 -- Start
        DataSet _dsResults = new DataSet();
        DataView dvResults = new DataView();
        SortedList _sPara = new SortedList();

        _sPara.Add("@CarId", Convert.ToInt64(Session[General.CarId].ToString()));
        _sPara.Add("@RefUserId", Convert.ToInt64(Session[General.UserId].ToString()));
        _dsResults = _db.GetDataSet("sprocCarInsuranceResultSelectItemList", _sPara);
        if (_dsResults.Tables.Count > 0 && _dsResults.Tables[0].Rows.Count > 0)
        {
            dvResults = _dsResults.Tables[0].DefaultView;
            dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";
        }
        //Sakthi on 18 Jan 2012 -- End

        dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";

        DataTable dtResults = dvResults.ToTable();

        bool IsGGSpecial = false;
        if (dtResults.Rows.Count > 0)
        {
            string _providercompanyid = dtResults.Rows[0]["providercompanyid"].ToString();
            //logo
            string logourl = "";
            string package = dtResults.Rows[0]["PackageName"].ToString();
            if (dtResults.Rows[0]["PackageName"].ToString() != "GluayGluay.com Special")
            {
                logourl = domainUrl + CE.Global.General.GetProviderCompanyLogo(_providercompanyid);
            }
            else
            {
                //[Yui] @13/09/2013
                IsGGSpecial = true;
                // --- End ---

                logourl = domainUrl + "/images/gg-logo/gluaygluay-logo.png";
                package += " (" + Resources.CarInsuranceResultPage.SpecialNCB + ")";
            }

            #region Main body

            #region Not Using
            float _fMonthlyPremiumAmount = Convert.ToSingle(dtResults.Rows[0]["MonthlyPremiumAmount"].ToString());
            string monthlyInstallment = "";

            if (_fMonthlyPremiumAmount > 0.0f)
            {
                string _monthlyPremiumAmount = String.Format("{0:0,0.00}", _fMonthlyPremiumAmount);
                monthlyInstallment = _monthlyPremiumAmount + "/mth<br/>";
            }
            else
            {
                monthlyInstallment = "<img src='" + domainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            #endregion

            _mailBody += "<table width='800' border='0' cellspacing='0' cellpadding='0'>";
            _mailBody += "<tr>";
            _mailBody += "<td height='129' valign='top'>";
            _mailBody += "<table width='500' border='0' cellspacing='1' cellpadding='1' bgcolor='#C1C1C1'>";

            #region Provider Logo & Package name
            _mailBody += "<tr>";
            _mailBody += "<td height='25' colspan='2' bgcolor='#FFFFFF' style='text-align: center;'>";
            _mailBody += "<span style='padding: 10px;'>";
            _mailBody += "<img src='" + logourl + "' alt='' /></span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            _mailBody += "<tr>";
            _mailBody += "<td width='517' height='25' bgcolor='#E7E7E7'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.ProposalForm.Package + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td width='276' height='25' bgcolor='#E7E7E7' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += package + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region Deductible
            float _fDEC = 0.0f;//Convert.ToSingle(dtResults.Rows[0]["DEC"].ToString());
            if (!float.TryParse(dtResults.Rows[0]["DEC"].ToString(), out _fDEC))
            {
                _fDEC = 0.0f;
            }
            string deductible = "";
            if (_fDEC > 0.0f)
            {
                deductible = String.Format("{0:0,0}", _fDEC);
            }
            else
            {
                deductible = Resources.CarInsuranceResultPage.Waived;
            }
            _mailBody += "<tr>";
            _mailBody += "<td width='450' height='25' bgcolor='#FFFFFF'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.DEC + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += deductible + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region Own Damage
            float _fDmg = 0.0f;//Convert.ToSingle(dtResults.Rows[0]["SumInsured"].ToString());
            if (!float.TryParse(dtResults.Rows[0]["SumInsured"].ToString(), out _fDmg))
            {
                _fDmg = 0.0f;
            }
            string suminsured = "";
            if (_fDmg > 0.0f)
            {
                suminsured = String.Format("{0:0,0}", _fDmg);
            }
            else
            {
                suminsured = "<img src='" + domainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.OwnDamage + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += suminsured + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region Fire
            float _fFire = 0.0f;//Convert.ToSingle(dtResults.Rows[0]["Fire"].ToString());
            if (!float.TryParse(dtResults.Rows[0]["Fire"].ToString(), out _fFire))
            {
                _fFire = 0.0f;
            }
            string fire = "";
            if (_fFire > 0.0f)
            {
                fire = String.Format("{0:0,0}", _fFire);
            }
            else
            {
                fire = "<img src='" + domainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.Fire + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += fire + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region Theft
            float _fTheft = 0.0f;//Convert.ToSingle(dtResults.Rows[0]["Theft"].ToString());
            if (!float.TryParse(dtResults.Rows[0]["Theft"].ToString(), out _fTheft))
            {
                _fTheft = 0.0f;
            }
            string theft = "";
            if (_fTheft > 0.0f)
            {
                theft = String.Format("{0:0,0}", _fTheft);
            }
            else
            {
                theft = "<img src='" + domainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.Theft + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += theft + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region TPPD
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.TPPD + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPPD"].ToString())) + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region TPBIA
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.TPBIA + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIA"].ToString())) + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region TPBIP
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.TPBIP + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIP"].ToString())) + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region PA Driver
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.PADriver + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["PADriver"].ToString())) + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region Medical Expense
            int _MedicalExpense = Convert.ToInt32(dtResults.Rows[0]["MedicalExpense"].ToString());
            string medicalExpense = "";
            if (_MedicalExpense == 0)
            {
                medicalExpense = "<img src='" + domainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            else
            {
                medicalExpense = String.Format("{0:#,0}", Convert.ToSingle(_MedicalExpense.ToString()));
            }
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.MED + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += medicalExpense + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region Bail Bond
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.BailBond + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#E7E7E7' style='text-align: right;'>";
            _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["BailBond"].ToString())) + "</span>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            #region CTPL
            if (_isCTPL == "Yes")
            {
                //premium before ctpl
                _mailBody += "<tr>";
                _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
                _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
                _mailBody += Resources.CarInsuranceResultPage.AnnualPremium + "</span>";
                _mailBody += "</td>";
                _mailBody += "<td height='25' bgcolor='#FFFFFF' style='text-align: right;'>";

                double BeforeCTPL = Convert.ToSingle(_Premium) - Convert.ToSingle(_CTPL);
                if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
                {
                    _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
                    _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + " " + Resources.CarInsurance.Baht + "</s></span><br />";
                }

                _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
                _mailBody += String.Format("{0:0,0.00}", Convert.ToSingle(BeforeCTPL)) + " " + Resources.CarInsurance.Baht + "</span>";
                _mailBody += "</td>";
                _mailBody += "</tr>";


                //CTPL Amount
                _mailBody += "<tr>";
                _mailBody += "<td height='25' bgcolor='#E7E7E7'>";
                _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
                _mailBody += Resources.Proposal.CTPL + "</span>";
                _mailBody += "</td>";
                _mailBody += "<td height='25' bgcolor='#E7E7E7' style='text-align: right;'>";
                _mailBody += "<span style='font-size: 14px; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
                _mailBody += String.Format("{0:0,0.00}", Convert.ToSingle(_CTPL)) + " " + Resources.CarInsurance.Baht + "</span>";
                _mailBody += "</td>";
                _mailBody += "</tr>";
            }
            #endregion

            #region Premium (+taxes & duties)
            _mailBody += "<tr>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF'>";
            _mailBody += "<span style='font-size: 14px; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += Resources.Proposal.TotalVMI + "</span>";
            _mailBody += "</td>";
            _mailBody += "<td height='25' bgcolor='#FFFFFF' style='text-align: right;'>";

            //Sakthi on 10 Nov 2014 - Start
            if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
            {
                _mailBody += "<span style='font-size: 16px; text-decoration: line-through; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
                _mailBody += String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + " " + Resources.CarInsurance.Baht + "</span><br />";
            }
            _mailBody += "<span style='font-size: 20px; color: #3A5999; padding-right: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            _mailBody += String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"].ToString())) + " " + Resources.CarInsurance.Baht + "</span>";
            //if (_isCTPL == "No")
            //{
            //    if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
            //    {
            //        _mailBody += "<span style='font-size: 16px; text-decoration: line-through; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            //        _mailBody += String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</span><br />";
            //    }
            //    _mailBody += "<span style='font-size: 20px; color: #3A5999; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            //    _mailBody += String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"].ToString())) + "</span>";
            //}
            //else
            //{
            //    _mailBody += "<span style='font-size: 20px; color: #3A5999; padding-left: 10px; padding-bottom: 5px; padding-top: 5px;'>";
            //    _mailBody += String.Format("{0:0,0.00}", Convert.ToSingle(_Premium)) + "</span>";
            //}
            //Sakthi on 10 Nov 2014 - End
            _mailBody += "</td>";
            _mailBody += "</tr>";
            #endregion

            _mailBody += "</table>";
            _mailBody += "</td>";
            _mailBody += "</tr>";
            _mailBody += "</table>";
            _mailBody += "<br />";
            #endregion
        }

        _mailBody += "<table style='line-height: 20px;' width='800' border='0' cellspacing='0' cellpadding='0'>";
        _mailBody += "<tr>";
        _mailBody += "<td width='787' height='26' colspan='4' bgcolor='#FFFFFF'>";

        #region BankIn Message
        _mailBody += "<strong><u>" + Resources.Proposal.ForBankIn + "</u></strong>";
        _mailBody += "<br />";
        _mailBody += Resources.Proposal.ForBankInMsg1;
        _mailBody += " ";
        _mailBody += Resources.Proposal.LineQrScan;
        _mailBody += "<br/><div style=\"text-align:center; width:400px\">";
        _mailBody += "<img runat=\"server\" id=\"imgSpecial\" alt=\"Line QR\" src=\"" + domainUrl + "/images/line-qr.jpg\" /></div>";

        _mailBody += "<br />";
        _mailBody += Resources.Proposal.ForBankInMsg2;
        _mailBody += "<br />";
        #endregion

        #region Remarks
        _mailBody += "<p>";
        _mailBody += "<strong>" + Resources.Proposal.Remarks + "</strong>";
        //[Yui] @13/09/2013
        if (!IsGGSpecial)
        {
            _mailBody += "<br/>" + Resources.Proposal.RemarksMsg1;
        }
        else
        {
            _mailBody += "<br/>" + Resources.Proposal.RemarksMsgGGSpecial;
        }
        _mailBody += "</p>";
        _mailBody += "<hr />";

        _mailBody += Resources.EmailMessage.FooterRisk;
        //_mailBody += "This Quote is subject to the insurer's final confirmation and coverage is only effective";
        //_mailBody += "when the";
        //_mailBody += "<br />";
        //_mailBody += "insurer has accepted the risk.";
        #endregion

        _mailBody += "</td>";
        _mailBody += "</tr>";
        _mailBody += "</table>";
        _mailBody += "<hr />";

        #region Footer

        _mailBody += "<table style='line-height: 20px;' width='800' border='0' cellspacing='0' cellpadding='0'>";
        _mailBody += "<tr>";
        _mailBody += "<td colspan='2' valign='top'>";
        _mailBody += "<strong>" + Resources.WelcomeEmail.CompanyAdd1 + "</strong><br />";
        _mailBody += Resources.WelcomeEmail.CompanyAdd2 + "<br />";
        _mailBody += Resources.WelcomeEmail.CompanyAdd3 + "<br />";
        _mailBody += Resources.WelcomeEmail.CompanyAdd4 + "<br />";
        _mailBody += Resources.WelcomeEmail.CompanyPhone + "<br />";
        _mailBody += Resources.WelcomeEmail.CompanyFax + "<br />";
        _mailBody += Resources.WelcomeEmail.CompanyEmail + "<br />";
        _mailBody += "</tr>";
        _mailBody += "</table>";
        _mailBody += "<br />";

        _mailBody += "<table width='300' border='0' align='center' cellpadding='0' cellspacing='0'>";
        _mailBody += "<tr>";
        _mailBody += "<td width='44' style='text-align: center'>";
        _mailBody += "<a href='https://www.facebook.com/GGmotor' target='_blank'><img src='" + domainUrl + "/images/icons/fb-big.png' width='44' height='42'></a>";
        _mailBody += "</td>";
        _mailBody += "<td width='44' style='text-align: center'>";
        _mailBody += "<a href='https://plus.google.com/+Gluaygluay/posts' target='_blank'><img src='" + domainUrl + "/images/icons/g-plus-big.png' width='44' height='42'></a>";
        _mailBody += "</td>";
        _mailBody += "<td width='44' style='text-align: center'>";
        _mailBody += "<a href='http://www.youtube.com/channel/UCZ4gMtlXymBHxvcXO2cR1vA' target='_blank'><img src='" + domainUrl + "/images/icons/youtube-big.png' width='44' height='42'></a>";
        _mailBody += "</td>";
        _mailBody += "<td width='44' style='text-align: center'>";
        _mailBody += "<a href='http://iconosquare.com/ggmotor' target='_blank'><img src='" + domainUrl + "/images/icons/instagram-big.png' width='44' height='42'></a>";
        _mailBody += "</td>";
        _mailBody += "<td width='43' style='text-align: center'>";
        _mailBody += "<a href='http://www.linkedin.com/company/-com-gluaygluay-com-' target='_blank'><img src='" + domainUrl + "/images/icons/linkedin-big.png' width='44' height='42'></a>";
        _mailBody += "</td>";
        _mailBody += "</tr>";
        _mailBody += "</table>";

        _mailBody += "<hr />";
        _mailBody += "<table style='line-height: 20px;' width='800' border='0' cellspacing='0' cellpadding='0' background='" + domainUrl + "/images/email-footer.jpg'>";
        _mailBody += "<tr>";
        _mailBody += "<td height='49'><br><p style='text-align: center'>© 2014 gluaygluay.com. All rights reserved.<br>";
        _mailBody += Resources.EmailMessage.AutoEmail + "</p></td>";
        _mailBody += "</tr>";
        _mailBody += "</table></td>";
        _mailBody += "</tr>";
        _mailBody += "</table>";
        _mailBody += "</body>";
        _mailBody += "</html>";
        #endregion

        #endregion


        if (MyMailManager.SendSelectedCARMessage(_emailTo, _emailSubject + " (Ref No : " + _refNo + ") ", _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    private bool SendProposalToUserNEW_Old(string CITempResultId)
    {
        Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());
        CE.User.Profile usrprofile = new Profile();
        ProfileDB usrprofiledb = new ProfileDB();

        usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

        string userfirstname = "";

        if (usrprofile != null)
        {
            userfirstname = usrprofile.FirstName;
        }

        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        string _Premium = "";
        string _Gender = "";
        string _DOB = "";
        string _Occupation = "";
        string _InsuranceType = "";
        string _NCB = "";

        string _GarageType = "";
        string _CarYear = "";
        string _CarMakeModel = "";
        string _CarType = "";
        string _CarPlate = "";
        string _NameDriver = "";
        string _Name = "";
        string _PolicyStartDate = "";

        string _isCTPL = "No";
        string _CTPL = "";

        Int64 _companyId = 0;

        System.Data.DataTable _dtSeletectItem = new System.Data.DataTable("SelectedResultItem");
        _dtSeletectItem = _db.GetDataTable("Select * from tblCarInsuranceSelectItemTH WHERE CarId = " + _carId.ToString());
        if (_dtSeletectItem != null && _dtSeletectItem.Rows.Count > 0)
        {
            _companyId = Convert.ToInt64(_dtSeletectItem.Rows[0]["ProviderCompanyId"].ToString());
            _Premium = Convert.ToSingle(_dtSeletectItem.Rows[0]["AnnualPremium"].ToString()).ToString("#.00");
        }
        CarInsuranceCompletedItemDB _carinsurancecompleteditemdb = new CarInsuranceCompletedItemDB();
        _dsInsurance = _carinsurancecompleteditemdb.GetCarInsuranceCompletedItem(_carId, _companyId);
        if (_dsInsurance != null && _dsInsurance.Tables[0].Rows.Count > 0)
        {
            _Gender = _dsInsurance.Tables[0].Rows[0]["Gender"].ToString() == "Male" ? Resources.CarInsurance.Male : Resources.CarInsurance.Female;
            _DOB = Convert.ToDateTime(_dsInsurance.Tables[0].Rows[0]["DOB"]).ToString("dd-MMM-yyyy");
            if (CE.Global.General.SetCulture() == "th-TH")
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["THOccupation"].ToString();
            }
            else
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["ENOccupation"].ToString();
            }
            switch (_dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString())
            {
                case "Class 1":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOne;
                    _NCB = _dsInsurance.Tables[0].Rows[0]["NCB"].ToString();
                    break;
                case "Class 1 (Low Cost)":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOneLowCost;
                    _NCB = "N/A";
                    break;
                case "Class 2+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    _NCB = "N/A";
                    break;
                case "Class 3+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThreePlus;
                    _NCB = "N/A";
                    break;
                case "Class 3":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThree;
                    _NCB = "N/A";
                    break;
            }
            _GarageType = _dsInsurance.Tables[0].Rows[0]["GarageType"].ToString() == "Authorized" ? Resources.CarInsurance.Garage_Authorized : Resources.CarInsurance.Garage_Dealer;
            _CarYear = _dsInsurance.Tables[0].Rows[0]["CarModelYear"].ToString();
            _CarMakeModel = _dsInsurance.Tables[0].Rows[0]["MakeModelDesc"].ToString();
            _CarType = _dsInsurance.Tables[0].Rows[0]["VehicleType"].ToString() == "Private Use" ? Resources.CarInsurance.VehicleType_Private : Resources.CarInsurance.VehicleType_Commercial;
            _NameDriver = _dsInsurance.Tables[0].Rows[0]["Driver"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesSpecify : Resources.CarInsurance.Option_NoSpecify;

            if (_dsInsurance.Tables[1].Rows.Count > 0)
            {
                _CarPlate = _dsInsurance.Tables[1].Rows[0]["VehicleNo"].ToString();
                if (_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"] != DBNull.Value)
                {
                    _PolicyStartDate = Convert.ToDateTime(_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"]).ToString("dd-MMM-yyyy");
                }
                _Name = _dsInsurance.Tables[1].Rows[0]["Name"].ToString();
                _refNo = _dsInsurance.Tables[1].Rows[0]["QuoteRefNo"].ToString();

                _isCTPL = _dsInsurance.Tables[1].Rows[0]["CTPL"].ToString();
                _CTPL = _dsInsurance.Tables[1].Rows[0]["CTPLAmount"].ToString();
            }
        }

        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

        string _emailTo = Session[General.UserEmail].ToString();
        //string _emailTo = "sophon.vorasitchai@comparexpress.com";
        string _customername = Session[General.UserName].ToString();
        string _emailSubject = "<Online> - " + Resources.EmailMessage.Subject; // "Your Car Insurance Quotes on CompareXpress(Thailand)";
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString(); //for testing
        //string _currentDomainUrl = "http://www.กล้วยๆ.com";
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center> <br /><br />";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
        _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
        _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.OrderConfirmation + "</strong><br /><br />";
        _mailBody += Resources.Proposal.ThankYou + "<br/><br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.OrderNo + "</strong> " + _refNo + "</td><td width='50%' align='right' valign='top'><img src='" + _currentDomainUrl + "/images/gg-logo/logo-gluaygluay.png' width='130' height='99'/></td></tr>";
        _mailBody += "</table>";

        _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        _mailBody += " <tr><td width='50%' valign='top'>" + Resources.Proposal.InsuranceType + " " + _InsuranceType + "</td><td width='50%;' valign='top'>&nbsp;</td>";
        _mailBody += "</tr><tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + General.GetUTCDateTime().ToString("dd/MMM/yyyy") + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.GarageType + ": " + _GarageType + "</td><td valign='top'>" + Resources.Proposal.NamedDrivers + ": " + _NameDriver + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.PolicyStartDate + ": " + _PolicyStartDate + " </td><td valign='top'>" + Resources.Proposal.NCB + ": " + _NCB + "</td></tr>";
        _mailBody += "</table> <br /><br />";

        //Sakthi on 18 Jan 2012 -- Start
        DataSet _dsResults = new DataSet();
        DataView dvResults = new DataView();
        SortedList _sPara = new SortedList();

        _sPara.Add("@CarId", Convert.ToInt64(Session[General.CarId].ToString()));
        _sPara.Add("@RefUserId", Convert.ToInt64(Session[General.UserId].ToString()));
        _dsResults = _db.GetDataSet("sprocCarInsuranceResultSelectItemList", _sPara);
        if (_dsResults.Tables.Count > 0 && _dsResults.Tables[0].Rows.Count > 0)
        {
            dvResults = _dsResults.Tables[0].DefaultView;
            dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";
        }
        //Sakthi on 18 Jan 2012 -- End

        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='100%' class='table_details'>";

        dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";

        DataTable dtResults = dvResults.ToTable();

        bool IsGGSpecial = false;
        if (dtResults.Rows.Count > 0)
        {
            string _providercompanyid = dtResults.Rows[0]["providercompanyid"].ToString();
            //logo
            string logourl = "";
            string insurername = dtResults.Rows[0]["PackageName"].ToString();
            if (dtResults.Rows[0]["PackageName"].ToString() != "GluayGluay.com Special")
            {
                logourl = CE.Global.General.GetProviderCompanyLogo(_providercompanyid);
            }
            else
            {
                //[Yui] @13/09/2013
                IsGGSpecial = true;
                // --- End ---

                logourl = "/images/gg-logo/gluaygluay-logo.png";
                insurername += " (" + Resources.CarInsuranceResultPage.SpecialNCB + ")";
            }

            _mailBody += "<tr>";
            _mailBody += "<td width='45%'></td>";
            _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
            _mailBody += "</tr>";

            //insurer name
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Insurer + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + insurername + "</strong></td>";
            _mailBody += "</tr>";


            float _fMonthlyPremiumAmount = Convert.ToSingle(dtResults.Rows[0]["MonthlyPremiumAmount"].ToString());
            string monthlyInstallment = "";

            if (_fMonthlyPremiumAmount > 0.0f)
            {
                string _monthlyPremiumAmount = String.Format("{0:0,0.00}", _fMonthlyPremiumAmount);
                monthlyInstallment = _monthlyPremiumAmount + "/mth<br/>";
            }
            else
            {
                monthlyInstallment = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }

            //Deductible  
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.DEC + "</strong></td>";
            float _fDEC = Convert.ToSingle(dtResults.Rows[0]["DEC"].ToString());
            string deductible = "";
            if (_fDEC > 0.0f)
            {
                deductible = String.Format("{0:0,0.00}", _fDEC);
            }
            else
            {
                deductible = Resources.CarInsuranceResultPage.Waived;  //"<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + deductible + "</td>";
            _mailBody += "</tr>";

            string suminsured = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["SumInsured"].ToString()));
            if (suminsured == "0")
            {
                suminsured = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            //Own Damage
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.OwnDamage + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + suminsured + "</td>";
            _mailBody += "</tr>";

            //Fire
            string fire = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Fire"].ToString()));
            if (fire == "0")
            {
                fire = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Fire + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + fire + "</td>";
            _mailBody += "</tr>";

            //Theft
            string theft = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Theft"].ToString()));
            if (theft == "0")
            {
                theft = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Theft + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + theft + "</td>";
            _mailBody += "</tr>";

            //TPPD
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.TPPD + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPPD"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //TPBIA
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIA + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIA"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //TPBIP
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIP + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIP"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //PA Driver
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.PADriver + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["PADriver"].ToString())) + "</td>";
            _mailBody += "</tr>";


            int _MedicalExpense = Convert.ToInt32(dtResults.Rows[0]["MedicalExpense"].ToString());
            string medicalExpense = "";

            if (_MedicalExpense == 0)
            {
                medicalExpense = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            else
            {
                medicalExpense = String.Format("{0:#,0}", Convert.ToSingle(_MedicalExpense.ToString()));
            }

            //Medical Expense
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.MED + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + medicalExpense + "</td>";
            _mailBody += "</tr>";

            //BB
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.BailBond + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["BailBond"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //CTPL
            if (_isCTPL == "Yes")
            {
                //premium before ctpl
                _mailBody += "<tr>";
                _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.AnnualPremium + "</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

                double BeforeCTPL = Convert.ToSingle(_Premium) - Convert.ToSingle(_CTPL);

                if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
                {
                    _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
                }

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(BeforeCTPL)) + "</strong>";
                _mailBody += "</td>";
                _mailBody += "</tr>";

                //ctplamount
                _mailBody += "<tr>";
                _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.CTPL + "</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5;'>";

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_CTPL)) + "</strong>";
                _mailBody += "</td>";
                _mailBody += "</tr>";
            }
            //premium
            _mailBody += "<tr>";
            _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.TotalVMI + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

            if (_isCTPL == "No")
            {
                if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
                {
                    _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
                }

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"].ToString())) + "</strong>";
            }
            else
            {
                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_Premium)) + "</strong>";
            }
            _mailBody += "</td>";
            _mailBody += "</tr>";
        }

        _mailBody += "</table>";
        _mailBody += "<br/><br/>";
        _mailBody += "<u>" + Resources.Proposal.ForBankIn + "</u>";
        _mailBody += "<br/>" + Resources.Proposal.ForBankInMsg1;
        _mailBody += "<br/>" + Resources.Proposal.LineQrScan;
        _mailBody += "<br/><div style=\"text-align:center; width:400px\">";
        _mailBody += "<img runat=\"server\" id=\"imgSpecial\" alt=\"Line QR\" src=\"" + _currentDomainUrl + "/images/line-qr.jpg\" /></div>";


        _mailBody += "<br/>";

        _mailBody += "<br/>" + Resources.Proposal.ForBankInMsg2;

        _mailBody += "<br/>";

        _mailBody += "<br/><strong>" + Resources.Proposal.Remarks + "</strong>";
        //[Yui] @13/09/2013
        if (!IsGGSpecial)
        {
            _mailBody += "<br/>" + Resources.Proposal.RemarksMsg1;
        }
        else
        {
            _mailBody += "<br/>" + Resources.Proposal.RemarksMsgGGSpecial;
        }
        _mailBody += "<br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.CompareXpress + "</strong>";
        _mailBody += "<br/>" + Resources.Proposal.CompareXpressAddress;

        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'>";
        _mailBody += "</td></tr></table>";

        _mailBody += "<hr />";
        _mailBody += Resources.EmailMessage.Footer;
        _mailBody += "<br/>";
        _mailBody += "<br /><i>" + Resources.EmailMessage.NoReply + "</i>";
        _mailBody += "<hr />";
        _mailBody += "</center></body>";

        if (MyMailManager.SendSelectedCARMessage(_emailTo, _emailSubject + " (Ref No : " + _refNo + ") ", _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    private bool SendProposalToAgent(string CITempResultId)
    {
        Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());
        CE.User.Profile usrprofile = new Profile();
        ProfileDB usrprofiledb = new ProfileDB();

        usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

        string userfirstname = "";

        if (usrprofile != null)
        {
            userfirstname = usrprofile.FirstName;
        }

        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        string _Premium = "";
        string _Gender = "";
        string _DOB = "";
        string _Occupation = "";
        string _InsuranceType = "";
        string _NCB = "";

        string _GarageType = "";
        string _CarYear = "";
        string _CarMakeModel = "";
        string _CarType = "";
        string _CarPlate = "";
        string _NameDriver = "";
        string _Name = "";
        string _PolicyStartDate = "";
        string _isCTPL = "No";
        string _CTPL = "";

        Int64 _companyId = 0;

        System.Data.DataTable _dtSeletectItem = new System.Data.DataTable("SelectedResultItem");
        _dtSeletectItem = _db.GetDataTable("Select * from tblCarInsuranceSelectItemTH WHERE CarId = " + _carId.ToString());
        if (_dtSeletectItem != null && _dtSeletectItem.Rows.Count > 0)
        {
            _companyId = Convert.ToInt64(_dtSeletectItem.Rows[0]["ProviderCompanyId"].ToString());
            _Premium = Convert.ToSingle(_dtSeletectItem.Rows[0]["AnnualPremium"].ToString()).ToString("#.00");
        }
        CarInsuranceCompletedItemDB _carinsurancecompleteditemdb = new CarInsuranceCompletedItemDB();
        _dsInsurance = _carinsurancecompleteditemdb.GetCarInsuranceCompletedItem(_carId, _companyId);
        if (_dsInsurance != null && _dsInsurance.Tables[0].Rows.Count > 0)
        {
            _Gender = _dsInsurance.Tables[0].Rows[0]["Gender"].ToString() == "Male" ? Resources.CarInsurance.Male : Resources.CarInsurance.Female;
            _DOB = Convert.ToDateTime(_dsInsurance.Tables[0].Rows[0]["DOB"]).ToString("dd-MMM-yyyy");
            if (CE.Global.General.SetCulture() == "th-TH")
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["THOccupation"].ToString();
            }
            else
            {
                _Occupation = _dsInsurance.Tables[0].Rows[0]["ENOccupation"].ToString();
            }
            switch (_dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString())
            {
                case "Class 1":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOne;
                    _NCB = _dsInsurance.Tables[0].Rows[0]["NCB"].ToString();
                    break;
                case "Class 1 (Low Cost)":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassOneLowCost;
                    _NCB = "N/A";
                    break;
                case "Class 2+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassTwoPlus;
                    _NCB = "N/A";
                    break;
                case "Class 3+":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThreePlus;
                    _NCB = "N/A";
                    break;
                case "Class 3":
                    _InsuranceType = Resources.CarInsurance.Insurance_ClassThree;
                    _NCB = "N/A";
                    break;
            }
            _GarageType = _dsInsurance.Tables[0].Rows[0]["GarageType"].ToString() == "Authorized" ? Resources.CarInsurance.Garage_Authorized : Resources.CarInsurance.Garage_Dealer;
            _CarYear = _dsInsurance.Tables[0].Rows[0]["CarModelYear"].ToString();
            _CarMakeModel = _dsInsurance.Tables[0].Rows[0]["MakeModelDesc"].ToString();
            _CarType = _dsInsurance.Tables[0].Rows[0]["VehicleType"].ToString() == "Private Use" ? Resources.CarInsurance.VehicleType_Private : Resources.CarInsurance.VehicleType_Commercial;
            _NameDriver = _dsInsurance.Tables[0].Rows[0]["Driver"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesSpecify : Resources.CarInsurance.Option_NoSpecify;

            if (_dsInsurance.Tables[1].Rows.Count > 0)
            {
                _CarPlate = _dsInsurance.Tables[1].Rows[0]["VehicleNo"].ToString();
                if (_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"] != DBNull.Value)
                {
                    _PolicyStartDate = Convert.ToDateTime(_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"]).ToString("dd-MMM-yyyy");
                }
                _Name = _dsInsurance.Tables[1].Rows[0]["Name"].ToString();
                _refNo = _dsInsurance.Tables[1].Rows[0]["QuoteRefNo"].ToString();

                _isCTPL = _dsInsurance.Tables[1].Rows[0]["CTPL"].ToString();
                _CTPL = _dsInsurance.Tables[1].Rows[0]["CTPLAmount"].ToString();
            }
        }

        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

        string _emailTo = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_TO"].ToString();
        string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_CC"].ToString();
        string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_BCC"].ToString();
        string _customername = Session[General.UserName].ToString();
        string _emailSubject = "<Online> - " + Resources.Proposal.PendingPayment + " - " + Resources.EmailMessage.ThaipaiboonSubject;
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center> <br /><br />";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
        _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
        if (Session[CE.Global.General.AgentId] != null && Session[CE.Global.General.AgentName] != null)
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.PendingPayment + " - " + Session[CE.Global.General.AgentName].ToString() + "</strong><br /><br />";
        }
        else
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.PendingPayment + "</strong><br /><br />";
        }
        _mailBody += Resources.Proposal.AgentMessage + "<br/><br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.OrderNo + " </strong>" + _refNo + "</td><td width='50%' align='right' valign='top'><img src='" + _currentDomainUrl + "/images/gg-logo/logo-gluaygluay.png' width='130' height='99'/></td></tr>";
        _mailBody += "</table>";

        _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        _mailBody += " <tr><td width='50%' valign='top'>" + Resources.Proposal.InsuranceType + " " + _InsuranceType + "</td><td width='50%;' valign='top'>&nbsp;</td>";
        _mailBody += "</tr><tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + General.GetUTCDateTime().ToString("dd/MMM/yyyy") + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.GarageType + ": " + _GarageType + "</td><td valign='top'>" + Resources.Proposal.NamedDrivers + ": " + _NameDriver + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.PolicyStartDate + ": " + _PolicyStartDate + " </td><td valign='top'>" + Resources.Proposal.NCB + ": " + _NCB + "</td></tr>";
        _mailBody += "</table> <br /><br />";

        //Sakthi on 18 Jan 2012 -- Start
        DataSet _dsResults = new DataSet();
        DataView dvResults = new DataView();
        SortedList _sPara = new SortedList();

        _sPara.Add("@CarId", Convert.ToInt64(Session[General.CarId].ToString()));
        _sPara.Add("@RefUserId", Convert.ToInt64(Session[General.UserId].ToString()));
        _dsResults = _db.GetDataSet("sprocCarInsuranceResultSelectItemList", _sPara);
        if (_dsResults.Tables.Count > 0 && _dsResults.Tables[0].Rows.Count > 0)
        {
            dvResults = _dsResults.Tables[0].DefaultView;
            dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";
        }
        //Sakthi on 18 Jan 2012 -- End

        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='100%' class='table_details'>";

        dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";

        DataTable dtResults = dvResults.ToTable();


        if (dtResults.Rows.Count > 0)
        {
            string _providercompanyid = dtResults.Rows[0]["providercompanyid"].ToString();
            //logo
            string logourl = "";
            string insurername = dtResults.Rows[0]["PackageName"].ToString();
            if (dtResults.Rows[0]["PackageName"].ToString() != "GluayGluay.com Special")
            {
                logourl = CE.Global.General.GetProviderCompanyLogo(_providercompanyid);
            }
            else
            {
                logourl = "/images/gg-logo/gluaygluay-logo.png";
                insurername += " (" + Resources.CarInsuranceResultPage.SpecialNCB + ")";
            }

            _mailBody += "<tr>";
            _mailBody += "<td width='45%'></td>";
            _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
            _mailBody += "</tr>";

            //insurer name
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Insurer + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + insurername + "</strong></td>";
            _mailBody += "</tr>";

            float _fMonthlyPremiumAmount = Convert.ToSingle(dtResults.Rows[0]["MonthlyPremiumAmount"].ToString());
            string monthlyInstallment = "";

            if (_fMonthlyPremiumAmount > 0.0f)
            {
                string _monthlyPremiumAmount = String.Format("{0:0,0.00}", _fMonthlyPremiumAmount);
                monthlyInstallment = _monthlyPremiumAmount + "/mth<br/>";
            }
            else
            {
                monthlyInstallment = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }

            //Deductible  
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.DEC + "</strong></td>";
            float _fDEC = Convert.ToSingle(dtResults.Rows[0]["DEC"].ToString());
            string deductible = "";
            if (_fDEC > 0.0f)
            {
                deductible = String.Format("{0:0,0.00}", _fDEC);
            }
            else
            {
                deductible = Resources.CarInsuranceResultPage.Waived;  //"<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + deductible + "</td>";
            _mailBody += "</tr>";

            string suminsured = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["SumInsured"].ToString()));
            if (suminsured == "0")
            {
                suminsured = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            //Own Damage
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.OwnDamage + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + suminsured + "</td>";
            _mailBody += "</tr>";

            //Fire
            string fire = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Fire"].ToString()));
            if (fire == "0")
            {
                fire = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Fire + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + fire + "</td>";
            _mailBody += "</tr>";

            //Theft
            string theft = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Theft"].ToString()));
            if (theft == "0")
            {
                theft = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Theft + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + theft + "</td>";
            _mailBody += "</tr>";

            //TPPD
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.TPPD + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPPD"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //TPBIA
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIA + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIA"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //TPBIP
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIP + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIP"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //PA Driver
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.PADriver + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["PADriver"].ToString())) + "</td>";
            _mailBody += "</tr>";


            int _MedicalExpense = Convert.ToInt32(dtResults.Rows[0]["MedicalExpense"].ToString());
            string medicalExpense = "";

            if (_MedicalExpense == 0)
            {
                medicalExpense = "<img src='" + _currentDomainUrl + "/images/icons/error.png' width='16' alt='NA' />";
            }
            else
            {
                medicalExpense = String.Format("{0:#,0}", Convert.ToSingle(_MedicalExpense.ToString()));
            }

            //Medical Expense
            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.MED + "</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + medicalExpense + "</td>";
            _mailBody += "</tr>";

            //BB
            _mailBody += "<tr>";
            _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.BailBond + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["BailBond"].ToString())) + "</td>";
            _mailBody += "</tr>";

            //CTPL
            if (_isCTPL == "Yes")
            {
                //premium before ctpl
                _mailBody += "<tr>";
                _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.AnnualPremium + "</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

                double BeforeCTPL = Convert.ToSingle(_Premium) - Convert.ToSingle(_CTPL);

                if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
                {
                    _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
                }

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(BeforeCTPL)) + "</strong>";
                _mailBody += "</td>";
                _mailBody += "</tr>";

                //ctplamount
                _mailBody += "<tr>";
                _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.CTPL + "</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5;'>";

                _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_CTPL)) + "</strong>";
                _mailBody += "</td>";
                _mailBody += "</tr>";
            }
            //premium
            _mailBody += "<tr>";
            _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.TotalVMI + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

            //Sakthi on 10 Nov 2014 - Start
            if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
            {
                _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
            }

            _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"].ToString())) + "</strong>";
            //if (_isCTPL == "No")
            //{
            //    if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
            //    {
            //        _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
            //    }

            //    _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"].ToString())) + "</strong>";
            //}
            //else
            //{
            //    _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_Premium)) + "</strong>";
            //}
            //Sakthi on 10 Nov 2014 - End
            _mailBody += "</td>";
            _mailBody += "</tr>";
        }
        _mailBody += "</table>";
        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'>";
        _mailBody += "</td></tr></table>";
        _mailBody += "</center></body>";

        if (MyMailManager.SendSelectedCARMessageToAgent(_emailTo, _emailCC, _emailBCC, _emailSubject + " (Ref No : " + _refNo + ") ", _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    protected void rdoMailingAddress_CheckedChanged(object sender, EventArgs e)
    {
        if (rdoMailingAddressYes.Checked)
        {
            rdoMailingAddressNo.Checked = false;
            pnlMailingAddress.Visible = false;

            rfvMailingAddress.Enabled = false;
            rfvMailingSubDistrict.Enabled = false;
            rfvMailingDistrict.Enabled = false;
            rfvMailingProvince.Enabled = false;
            rfvMailingPostalCode.Enabled = false;
            revMailingPostalCode.Enabled = false;

            txtMailingAddress.Text = "";
            ddlMailingSubDistrict.SelectedValue = "-1";
            ddlMailingDistrict.SelectedValue = "-1";
            ddlMailingProvince.SelectedValue = "-1";
            txtMailingPostalCode.Text = "";
        }
        else if (rdoMailingAddressNo.Checked)
        {
            rdoMailingAddressYes.Checked = false;
            pnlMailingAddress.Visible = true;

            BindDdlMailingProvince();
            rfvMailingAddress.Enabled = true;
            rfvMailingSubDistrict.Enabled = true;
            rfvMailingDistrict.Enabled = true;
            rfvMailingProvince.Enabled = true;
            rfvMailingPostalCode.Enabled = true;
            revMailingPostalCode.Enabled = true;
        }
    }

    //[Yui] @13/09/2013
    private void SaveConfirmDisclaimer(int ProviderId, long CECarMoreDetailId)
    {
        try
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocCarMoreDetailUpdateSingleItemDisclaimer]";
            SortedList _spList = new SortedList();
            _spList.Add("@ProviderId", ProviderId);
            _spList.Add("@CECarMoreDetailId", CECarMoreDetailId);
            Int64 _retValue = _db.ExecuteSP(_spName, _spList);
            //return _retValue == 1;
        }
        catch (Exception)
        {

            throw;
        }
    }

    #region Sakthi changes on 27 Oct 2014

    protected void rdoYesAddDriver_CheckedChanged(object sender, EventArgs e)
    {
        if (rdoYesAddDriver.Checked)
        {
            rdoNoAddDriver.Checked = false;
            divNoofDriver.Visible = true;
            EnableDriverPanels();
        }
    }

    protected void rdoNoAddDriver_CheckedChanged(object sender, EventArgs e)
    {
        if (rdoNoAddDriver.Checked)
        {
            rdoYesAddDriver.Checked = false;
            divNoofDriver.Visible = false;
            EnableDriverPanels();
        }

    }

    protected void ddlDriverCount_SelectedIndexChanged(object sender, EventArgs e)
    {
        EnableDriverPanels();
    }

    public bool ValidDate(Int32 Year, Int32 Month, Int32 Day)
    {
        bool _isValid = true;
        int daysInMonth = 0;
        string leap, monthValid, dayValid, yearValid;
        if (Year >= 0000)
        {
            yearValid = "yes";
        }
        else
        {
            yearValid = "no";
        }
        if (Year % 400 == 0)
        {
            leap = "yes";
        }
        else if (Year % 100 == 0)
        {
            leap = "no";
        }
        else if (Year % 4 == 0)
        {
            leap = "yes";
        }
        else
        {
            leap = "no";
        }

        switch (Month)
        {
            case 1: daysInMonth = 31;
                break;
            case 3: daysInMonth = 31;
                break;
            case 4: daysInMonth = 30;
                break;
            case 5: daysInMonth = 31;
                break;
            case 6: daysInMonth = 30;
                break;
            case 7: daysInMonth = 31;
                break;
            case 8: daysInMonth = 31;
                break;
            case 9: daysInMonth = 30;
                break;
            case 10: daysInMonth = 31;
                break;
            case 11: daysInMonth = 30;
                break;
            case 12: daysInMonth = 31;
                break;
        }

        if (Month >= 1 && Month <= 12)
        {
            monthValid = "yes";
        }
        else
        {
            monthValid = "no";
        }
        if (Month == 2)
        {
            if (leap == "no")
            {
                daysInMonth = 28;
            }
            else if (leap == "yes")
            {
                daysInMonth = 29;
            }
        }

        if (1 <= Day && Day <= daysInMonth)
        {
            dayValid = "yes";
        }

        else
        {
            dayValid = "no";
        }

        if ((dayValid == "yes") && (monthValid == "yes") && (yearValid == "yes"))
        {
            _isValid = true;
        }
        else
        {
            _isValid = false;
        }

        return _isValid;
    }

    #endregion

    private void CheckMailingAddress()
    {
        if (hidMailingAddress.Value == "no")
        {
            rdoMailingAddressNo.Checked = false;
            pnlMailingAddress.Visible = false;

            rfvMailingAddress.Enabled = false;
            rfvMailingSubDistrict.Enabled = false;
            rfvMailingDistrict.Enabled = false;
            rfvMailingProvince.Enabled = false;
            rfvMailingPostalCode.Enabled = false;
            revMailingPostalCode.Enabled = false;

            txtMailingAddress.Text = "";
            ddlMailingSubDistrict.SelectedValue = "-1";
            ddlMailingDistrict.SelectedValue = "-1";
            ddlMailingProvince.SelectedValue = "-1";
            txtMailingPostalCode.Text = "";
        }
    }
}
